#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar display_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uint Count=0;
sbit AN3=P2^0;
void delay()
{
uchar i;
for(i=250;i>0;i--);
}
void disp()
{
P3=0x01;
P0=display_code[Count/100/10];
delay();
P3=0x00;
P3=0x02;
P0=display_code[Count/100%10];
delay();
P3=0x00;
P3=0x04;
P0=display_code[Count/10];
delay();
P3=0x00;
P3=0x08;
P0=display_code[Count%10];
delay();
P3=0x00;
}
void main()
{
uint i;
while(1)
{
if(AN3==0)
{
Count++;
while(AN3==0);
if(Count>9999) Count=0;
}
for(i=100;i>0;i--)
{
disp();
}
}
}