单片机,要求使用中断的方式,我按照要求做了,为什么keyflag在break之后就没法进去了,数组循环也存在问题。
单片机源程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table0[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar code table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar code table2[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
uchar code table3[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};
uchar code table4[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
uchar code table5[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f};
uchar code table6[]={0xfe,0xfc,0xfa,0xf6,0xee,0xde,0xbe,0x7e};
uchar code table7[]={0x7f,0x3f,0x5f,0x6f,0x77,0x7b,0x7d,0x7e};
void Ex_init();
void delayms(uint z);
uchar keyflag =0;
void asd();
uchar i;
void main()
{ uchar i;
Ex_init();
while(1)
{
switch(keyflag)
{ case 0:P1=0X00; break;
case 1:P1=0XFF; break;
case 2:P1=table0[ i];break;
case 3:P1=table1[ i];break;
case 4:P1=table2[ i];break;
case 5:P1=table3[ i];break;
case 6:P1=table4[ i];break;
case 7:P1=table5[ i];break;
case 8:P1=table6[ i];break;
case 9:P1=table7[ i];break;
default:break;
}
i=i++;
delayms(1);
}
}
void delayms(uint z)
{ uint a,b;
for(a=0;a<z;z++)
for(b=0;b<120;b++);
}
void Ex_init()
{ IT1=1;
EX1=1;
PX1=1;
EA=1;
}
void key_int()interrupt 2
{ keyflag++;
IE0=0;
}
|