我用8051的硬件中断0编写了一个简单的led闪烁代码。 当按钮被按下时,它进入中断服务程序(ISR)。执行后它应该返回到主函数中,但它没有出现。 这是我的c代码。任何积极的答复将不胜感激。
sbit LED = P1^0;
void delay(int ms)
{
int i;
for(i=0;i<ms;i++)
{
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x66;
TR0 = 1;
while(TF0==0);
TR0 = 0;
TF0 = 0;
}
}
void main(void)
{
P1 = 0x00;
/// P3 = 0x04;
IT0 = 1;
EX0 = 1;
EA = 1;
LED=1;
while(1)
{
LED=~LED;
delay(200);
}
return ;
}
void external0_isr() interrupt 0
{
EA=0;
LED =0 ;
delay(2000);
LED=1;
EX0=1;
EA=1;
return;
}
最佳答案
进入按钮中断时,禁用全局中断EA=0;
这也会禁用定时器中断。因此,您的程序将卡在 delay(2000)
例程中的 while(TF0==0)
处。
关于c - 如何结束8051中的外部中断服务程序(ISR),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41389051/