小弟在学单片机外部中断时写了这么个程序(见笑)。我设想的结果是单片机上电时数码管出现8051,按一次按键出现1,再按一次出现2,一直按5次,出现good。可是只有刚开始8051是出现了,按一次也出现1,再按一次没有出现2。我估计是程序出现了很大问题。诸位大哥可不可以帮我看看
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar t=0;
uint seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay(uint x);
void main()
{
IT0=1;
EX0=1;
EA=1;
while(t==0){
P0=0xf7;
P1=0xf9;
delay(3);
P0=0xfb;
P1=0x92;
delay(3);
P0=0xfd;
P1=0xc0;
delay(3);
P0=0xfe;
P1=0x80;
delay(3);}
while(t!=0)
{
P0=0x1f;
P1=seg[t];
}
}
void delay(uint x)
{uint i,j;
for(i=x;i>0;i--)
for(j=112;j>0;j--){;}
}
void X_INT(void) interrupt 0
{EX0=0;
P1=0xff;
t+=1;
delay(1000);
if(t==5)
{P0=0xf7;
P1=0xa1;
delay(3);
P0=0xfb;
P1=0xc0;
delay(3);
P0=0xfd;
P1=0xc0;
delay(3);
P0=0xfe;
P1=0x90;
delay(3);}
while(P3&0x04==0);
EX0=1;
} |