#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5c,0x79,0x71};
uint num,aa,fhz;
uchar shi,ge,bai,qian,sh,sh0,fen0,fen,sh1,fen1;
void delayms(int);
void intin();
void main()
{
intin();
while(1)
{
}
}
void intin()
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(aa==2)
{
aa=0;
num++;
if(num==600)
{
num=0;
fen++;
if(fen==60)
{
fen=0;
sh++;
if(sh==12)
{
sh=1;
}
}
}
}
bai=num/100;
shi=num%100/10;
ge=num%10;
fen1=fen/10;
fen0=fen%10;
sh1=sh/100;
sh0=sh%10;
P2=0xfb;
P0=table[bai];
delayms(1);
P2=0xfd; //打開第二位
P0=table[shi]; //送十位段數據
delayms(1);
P2=0xfe; //打開第一位
P0=table[ge]; //送各位段數據
delayms(1);
P2=0x7f;
P0=table[sh1]; //時
delayms(1);
P2=0xbf;
P0=table[sh0];
delayms(1);
P2=0xef;
P0=table[fen1]; //分
delayms(1);
P2=0xf7;
P0=table[fen0];
delayms(1);
}
}
void delayms(int xsm)
{
int i,j;
for(i=xsm;i>0;i--)
for(j=110;j>0;j--);
}
void time0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
aa++;
}
|