
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //LED0-9
uchar data_L,data_H; //high bite and low bite
uchar t,a; //count
void delay(uint k) //delay about 0.1ms
{
uint m,n;
for(m=0;m<k;m++)
{
for(n=0;n<120;n++);
}
}
void display (void) //display program
{
P2=0x01;
P0=tab[data_H];
delay(1);
P2=0x02;
P0=tab[data_L];
delay(1);
}
void Timer0() interrupt 1 //50ms timing
{
t++;
TH0=0x4c; //11.0592MHz initial value at high bits
TL0=0x00; //11.0592MHz initial value at low bits
}
void data_tim(void) //59s cuont
{
if(t==20)
{
a++;
t=0;
if(a==60)
{
a=0;
}
}
}
void data_in(void) //cut value
{
data_L=a%10;
data_H=a/10;
}
void T0_init(void) //T0 initialization
{
TMOD=0x01; //T0 count model 1
TH0=0x4C;
TL0=0x00;
ET0=1; //allow T0 break
TR0=1; //state T0
EA=1;
}
void main(void)
{
a=0;
T0_init();
while(1)
{
data_tim();
data_in();
display();
}
}