中断函数调用vs正常函数

问题描述 投票:-2回答:1

在微控制器中,编译器如何区分中断函数和任何其他函数,例如在pic16f877中的Rb0中断,当标志值改变时调用中断函数,为什么它没有调用代码中的任何其他函数。

c++ c microcontroller pic
1个回答
2
投票

当你提到interrupt function时,我认为你的意思是中断服务常规。 ISR是C函数,已被标记为插入硬件中断向量表。

这是一个例子:

void __interrupt Rb0_Isr(void);

或(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 */
    }
}

如您所见,它取决于平台和编译器。

编辑:感谢@ThomasMatthews的评论。 ISR也可以用C ++实现。如果问题是:Is it possible to use a class method as the Interrupt Service Routine?答案是肯定的,但有点复杂。请参阅主题:C++ ISR using class method?

© www.soinside.com 2019 - 2024. All rights reserved.