Work with C interruptions by compiling for pc

Asked

Viewed 1,582 times

4

While trying to answer a question from the site I started a dense survey of how to work with C interruptions.

Interruptions for those who did not understand it works as follows:

Tstou running my program normally, as soon as a certain thing happens, regardless of where I am in my program, I run an X function.

In computer programming, using the C language as well, 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 it works:

I’m running my main program and as soon as the accountant counts 128ms it performs the function TIMER0_isr(); that is, that is an interruption of time, to each 128ms run function x.

There are also other types of interruption for processors, such as keyboard, you can set an X function to be executed whenever someone presses a key.

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

How do I do that?

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

  • It would be in Windows, or DOS?

  • 1

    Summarily, the onclicklistener Java probably generates an event to be processed in the thread with the event looping, the event being processed as soon as the thread becomes Idle. An interruption is much lower level than this, and behaves completely different, in addition to being implemented at the driver level. Be more specific about the operating system and how much you want to be specific about it.

  • in fact, I’m not creating an application, it’s more curious, so I didn’t put S.O. on this being high level and different behavior I also know, but the end result is the same and that’s what matters

1 answer

1


If when you write PC means Windows, your problems just started. Joke, actually they will become 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 minimum security and best practices, could corrupt the system as a whole.
In short, for the most current versions of the operating system, you should use drivers developed in WDK to be able to access interruptions and thus be able to create events that can be triggered for user-mode applications, as drivers run in privileged mode.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.