C51外中断程序
扫描二维码
随时随地手机看文章
没有中断时以流水灯显示,外中断0使左右4个LED交替闪烁,外中断1使LED闪亮,
#include
unsigned char code design[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x00};
void Delay(unsigned int i){
unsigned int j;
for(;i>0;i--)
for(j=0;j<125;j++);
}
void main(){
unsigned char i;
EA=1;
EX0=1;
EX1=1;
IT0=1; //脉冲触发方式
IT1=0; //使用电平触发
PX0=0;
PX1=0;
while(1){
for(i=0;i<=9;i++){
P1=design[i];
Delay(500);
}
}
while(1);
}
void int0_int(void) interrupt 0{
EX0=0;
P1=0xf0;
Delay(5000);
P1=0x0f;
Delay(5000);
EX0=1;
}
void int1_int(void) interrupt 2{
EX1=0;
P1=0x00;
Delay(5000);
P1=0xff;
Delay(5000);
EX1=1;
}