#include <REG52.H>
#define uchar unsigned char
sbit dula=P2^6;//段
sbit wela=P2^7;//位
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c
,0x39,0x5e,0x79,0x71};
uchar flag_1s,flag_60s,flag_light,num_small,num_big;
//延时函数
void delay(uchar i){
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void display(uchar a,uchar b){
P0=table[a];
dula=1;
dula=0;
P0=0xef;
wela=1;
wela=0;
delay(5);
P0=table[b];
dula=1;
dula=0;
P0=0xdf;
wela=1;
wela=0;
delay(5);
}
void main(){
TMOD=0x01;//定时器0 工作模式1
TR0=1;//打开定时器
TH0=(655360-46080)/256;//11Mhz下50000us=46080发起一次中断
TL0=(65536-46080)%256;
while (1)
{
if(TF0==1){//中断溢出标志
TF0=0;
flag_1s++;
TH0=(655360-46080)/256;
TL0=(65536-46080)%256;
}
if(flag_1s==20)//20*50ms=1s
{
flag_1s=0;
flag_60s++;
flag_light++;
P1=flag_light;
if(flag_60s==60){
flag_60s=0;
}
}
num_small=flag_60s%10;
num_big=flag_60s/10;
display(num_big,num_small);
}
}