進入中斷后,關閉中斷,執(zhí)行中斷程序里的代碼完后,再打開,還是可以進入中斷的.
但是一般不這么寫,更多的是某中斷執(zhí)行完其代碼后,將自身使能位關閉,然后再其他中斷或者main函數(shù)里根據(jù)需要條件觸發(fā)再打開,如.
void main(void)
{
.....
......
while(1)
{
....
.....
if(xxxx&&ex0==0)
{
ex0 = 1;
}
............
............
}
}
void ex0_ISR() interrupt 0
{
.............
...............
.................
ex0 = 0;
}
建議中斷程序里盡量不要寫循環(huán),更加不應該寫DELAY,完全可以通過寫IF來判斷,然后設置標志位,main函數(shù)再根據(jù)標志位來執(zhí)行對應的功能.如:
bit flag_1;
void main(void)
{
while(1)
{
if(flag_1==1)
{
while(xxx)
{
.............
...........
}
delay(xxxx);
flag_1 = 0;
ex0 = 1;
}
}
}
void ex0_ISR() interrupt 0
{
ex0 = 0;
flag_1 = 1;
} |