#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit clear = P3^4;
uchar code DSY_CODE[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff
};
uchar code Scan_BITs[]=
{
0x20,0x10,0x08,0x04,0x02,0x01
};
uchar data Buffer_Counts[]={0,0,0,0,0,0};
uint Count=0;
void DelayMS(uint x)
{
uchar t;
while(x--)
{
for(t=0;t<120;t++);
}
}
void Show_Counts()
{
uint i;
Buffer_Counts[3] = Count / 1000;
Buffer_Counts[2] = Count % 1000 / 100;
Buffer_Counts[1] = Count % 100 / 10;
Buffer_Counts[0] = Count % 10;
for(i=0;i<4;i++)
{
P2 = Scan_BITs[i];
if(Buffer_Counts[i]==0)
P1=0xC0;
else
{
P1 = DSY_CODE[Buffer_Counts[i]];
}
DelayMS(1);
}
}
void main()
{
IT0 = 1;
IE = 0x81;
while(1)
{
if(clear == 0) Count = 0;
Show_Counts();
}
}
void EX_INT0() interrupt 0
{
Count++;
}