單片機中斷實驗3
代碼如下:
#include
#include
sbit p1_0 = P1^0;
sbit p1_1 = P1^1;
void delay (void) {
int a = 500;
while(a--) _nop_();
}
void LED_01() interrupt 0 using 1 {
delay();
if (INT0 == 0) {
p1_0 = !p1_0;
while (INT0 == 0);
}
}
void LED_02() interrupt 2 using 1 {
delay ();
if (INT1 == 0) {
p1_1 = !p1_1;
while (INT1 == 0);
}
}
void main () {
p1_0 = 0;
p1_1 = 0;
EA = 1;
EX0 = 1;
EX1 = 1;
PX0 = 0; //中斷比px1低 當高位中斷進行時,低位中斷不能打斷高位的中斷
PX1 = 1; //中斷比px0高 當低位中斷進行時,高位中斷可以打斷低位中斷
while(1);
}
評論