#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//0-9
uchar scanled;
uchar disdat[4];
uint ss,time;
sbit led=P1^0;
void dischg()
{
disdat[3]=ss%10;
disdat[2]=(ss/10)%10;
disdat[1]=(ss/100)%10;
disdat[0]=(ss/1000)%10;
}
void t0isr() interrupt 1
{
ss++;
dischg();
}
void t1isr() interrupt 3 //显示
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
P2=1<<scanled;
P0=~ledtab[disdat[scanled]];
scanled++;
scanled%=4;
time++;
if(time>100){time=0;led=~led;}
}
main()
{
TMOD=0x16;
TH0=0xff;
TL0=0xff;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
led=0;
scanled=0;
ss=0;
dischg();
while(1);
}