我写了一个简单的LED闪烁代码,硬件中断0为8051。 按下按钮后,进入中断服务程序(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;
}
答案 0 :(得分:1)
当您输入按钮中断时,您将禁用全局中断900px
这也会禁用定时器中断。因此,您的程序将在EA=0;
例程while(TF0==0)
处挂起。