Working with interrupts in C compiling for pc

4

When trying to answer a question on the site I started a dense search of how to work with interrupts in C.

Interruptions for those who did not understand works as follows:

I'm running my program normally, as soon as something happens, regardless of where I am in my program, I run an X function.

In processor programming, the C language is also used, it works like this:

    int duty;//duty 0-100

#int_TIMER0
void  TIMER0_isr(void) 
{

   int led;
   set_timer0(128);
   if(led==0/*&&duty<contador*/)
   {
      led=1;
   }
   else {led=0;}
   output_bit (PIN_B5,led);

}


void main()
{

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);

   // TODO: USER CODE!!


   while(true)
   {
      //aqui meu programa principal

   }
}

How this works:

I am running my main program and as soon as the counter counts 128ms it executes the TIMER0_isr(); function ie this is a time interrupt, every 128ms run the function x.

There are also other interrupt types for processors, such as the keyboard, you can set an X function to run whenever someone presses a key.

What I researched so much and did not find, how to do this compiling to a PC. that is, I want to make my program run perfectly and whenever someone presses a key on the keyboard I execute a function y. Or when it bursts a certain time I execute a function z.

How do I do this?

(something like the onclicklistner method of java would also work)

    
asked by anonymous 07.11.2014 / 19:50

1 answer

1

If when you write PC means Windows, your problems just started. Joke, in fact will be more complex, because the Windows operating system abstracts the hardware of the applications. This is what makes the system and its applications more reliable. Otherwise, any application, without the minimum of security and good practices, could corrupt the system as a whole. In summary, for the most current versions of the operating system, you should use drivers developed at WDK to be able to access interrupts and thus be able to create events that can be triggered for applications in user mode, because drivers run in privileged mode.

    
08.11.2014 / 17:09