电路图:
代码如下:
#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);
}