这个程序写的有缺陷,请各位大侠帮忙优化下。是个响应外部中断1的简单程序。
#include < reg52.h >
#define uchar unsigned char
sbit int1=P3^3;
unsigned char code LEDData[11] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff};
unsigned char data display[3] = {0x00,0x00,0x00};
unsigned char code scan_bit[4] = {0xf7,0xfb,0xfd};
unsigned char count=0,a;
void delay(uchar x)
{
uchar k;
while(x--)
{
for(k=0;k<100;k++);
}
}
void main(void)
{
char n;
EA=1;
EX1=1;
while(1)
{
for(n=0;n<3;n++)
{
P2=scan_bit[n];
P0 =LEDData[display[n]] ;
delay(1);
}
}
}
void counter(void) interrupt 2
{
count++;
while(!int1)
{
a=count;
display[2]=a/100;
a=a%100;
display[1]=a/10;
display[0]=a%10;
}
} |