程序如下
#include
#define uchar unsigned char
#define uint unsigned int
sbit tab=P3^2;
sbit start=P3^3;
bit timeover=0;
uchar led_count=0;
uchar disBuf[8];
uchar code disp_code[]=
{
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
//0-9
0x88,0x83,0xC6,0xA1,0x86,0x8E,
//A B C D E F
0x7F,0xBF,0x9C,0xFF
//. - o null
};
uint time,num=9999;
uint w1=0,w2=0,w3=0,w4=0;
unsigned int i,j;
void delay(uint del)
{
for(;del>0;del--);
}
void main(void)
{
disBuf[7]=19;
disBuf[6]=19;
disBuf[5]=19;
disBuf[4]=19;
disBuf[3]=10;
disBuf[2]=10;
disBuf[1]=10;
disBuf[0]=10;
while(1)
{
time=num;
do {
if(tab==0)
{
if(time!=9)
time=time/10;
else
time=9999;
}
P0=0xFF;
P1=~(1<<(led_count%8));
P0=disp_code[disBuf[led_count%8]];
led_count++;
}
while(start==0);
num=time;
while(timeover=0)
{
while(time>0)
{
for(i=0;i<18879;i++)
{
P0=0xff;
P1=~(1<<(led_count%8));
P0=disp_code[disBuf[led_count%8]];
led_count++;
w1=time%10;
w2=time/10%10;
w3=time/100%10;
w4=time/1000%10;
disBuf[3]=w4;
disBuf[2]=w3;
disBuf[1]=w2;
disBuf[0]=w1;
}
time--;
}
timeover=1;
}
}
}



