#include<reg52.h>
#define uchar unsigned char
code uchar xianshi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit gw=P2^4;
sbit sw=P2^5;
sbit bw=P2^6;
sbit qw=P2^7;
uchar k,pl,m,pl0,k0,m0;
void delay(unsigned int tc)
{
unsigned int i;
for(i=0;i<125;i++)
{;}
tc--;
}
void LED()
{
gw=0;
P0=xianshi[pl0%10];
delay(10);
gw=1;
sw=0;
P0=xianshi[pl0/10];
delay(8);
sw=1;
bw=0;
P0=xianshi[k0];
delay(6);
bw=1;
qw=0;
P0=xianshi[m0];
delay(4);
qw=1;
}
void t0(void) interrupt 1 //定时中断服务函数
{
static unsigned int tcnt=0,sec=0;
tcnt++; //每过250ust tcnt 加一
if(tcnt==400) //计满400 次(1/10 秒)时
{
tcnt=0; //重新再计
sec++;
if(sec==10) //定时10 秒,在从零开始计时
{
sec=0;
pl0=pl;k0=k;m0=m;
pl=0;k=0;m=0;
}
}
}
void t1in(void) interrupt 3
{
pl++;
TH1=0xff;
TL1=0xff;
if(pl>99)
{
k++;
pl=0;
}
if(k>9)
{
m++;
k=0;
}
if(m>9)
{
m=0;
k=0;
pl=0;
}
}
void main(void)
{
EA=1;
IP=0x02;
TH0=TL0=0x1b;
TMOD=0x52;
IE=0x8A;
TH1=0xff;
TL1=0xff;
TR0=1;
TR1=1;
while(1)
{
LED();
}
}