-2

In microcontroller, how do the compiler distinguish between the interrupt function and any other function, as an example in Rb0 interrupt in the pic16f877, when the flag value changes it calls the interrupt function, why it didn't call any other function in the code.

7
  • 2
    Because usually the function which handles the interrupt is marked/tagged as such. How this is done is platform dependent. Commented Mar 11, 2019 at 13:03
  • I am not familiar with the Rb0 interrupt Bakr, but I just had a quick search, and it seems like the 'interrupt' keyword is used to mark a function, and in the function the the external interrupt flag INTF is checked, if it is 1 then the Rb0 interrupt has occured. 'INTE' needs to be set to 1 to enable external interrupt. Hope it is some help. Commented Mar 11, 2019 at 13:11
  • I think your question is too broad, as the type of interrupt and microcontroller may well be important. If you care specifically about your example then you should rephrase your question about that. Commented Mar 11, 2019 at 13:28
  • I ask generally not this type specifically, if i had : void a and void b, how could the complier know that void b is the inrerrupt function. Commented Mar 11, 2019 at 13:30
  • @BakrHesham the compiler cannot know which one is an interrupt function and which one is not. How could that be possible? Usually there is a special keyword or a pragma or whatever platform specific way to tell the compiler that some function is an interrupt function. Commented Mar 11, 2019 at 13:33

1 Answer 1

2

I think you mean Interrupt Service Routine when you refer to interrupt function. An ISR is a C function which has been flagged to be inserted in the hardware Interrupt Vector Table.

Here's an example:

void __interrupt Rb0_Isr(void);

or (link)

unsigned int  interruptcnt;
unsigned char second;

void timer0 (void) interrupt 1 using 2  {
    if (++interruptcnt == 4000)  {    /* count to 4000 */
        second++;                       /* second counter    */
        interruptcnt = 0;               /* clear int counter */
    }
}

As you see, it depends on the platform and on the compiler.

EDIT: thanks to @ThomasMatthews for the remark. ISRs can be implemented in C++ as well. If the question is: Is it possible to use a class method as the Interrupt Service Routine? the answer is yes but a bit more complicated. See the topic: C++ ISR using class method?

Sign up to request clarification or add additional context in comments.

1 Comment

Can the ISR be a C++ function? (Your comment states it is a C function). After all, it's just an address in a table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.