1.外部中断专用
#include <REGX52.H>
unsigned char flag = 0;
unsigned char led[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void Delay1ms(unsigned char ms){
unsigned char k;
while(ms--){
for(k = 0;k < 113; k++);
}
}
void main(){
P1 = 0;
IT0 = 1;
IT1 = 1;
EA = 1;
EX1 = 1;
EX0 = 1;
while(1){
P1 = led[flag];
Delay1ms(10); //按键防抖
}
}
void INT0_ISR() interrupt 0
{
EX0 = 0;
if(++flag == 8) flag = 0;
EX0 = 1;
}
void INT1_ISR() interrupt 2
{
EX1 = 0;
if(--flag == 255) flag = 7;
EX1 = 1;
}