#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,0x8e,0x00,0xbf};
uint a=0;
uint b=0;
uint c=0;
uchar day=0;
uchar ch=0;
uchar ch1=0;
uchar ch2=0;
uchar shi=0;
uchar shi1=0;
uchar shi2=0;
uchar fen=0;
uchar fen1=0;
uchar fen2=0;
uchar miao=0;
uchar miao1=0;
uchar miao2=0;
//延时
void DelayMS(uint x)
{
uchar i;
while(x--) for(i=0;i<120;i++);
}
void xianshi()
{
while(1)
{
ch=ch%10;
ch=ch/10;
shi1=shi%10;
shi2=shi/10;
fen1=fen%10;
fen2=fen/10;
miao1=miao%10;
miao2=miao/10;
P2=0x80;
P0=DSY_CODE[miao1];
DelayMS(5);
P2=0x00;
P2=0x40;
P0=DSY_CODE[miao2];
DelayMS(5);
P2=0x00;
P2=0x20;
P0=DSY_CODE[fen1];
DelayMS(5);
P2=0x00;
P2=0x10;
P0=DSY_CODE[fen2];
DelayMS(5);
P2=0x00;
P2=0x08;
P0=DSY_CODE[shi1];
DelayMS(5);
P2=0x00;
P2=0x04;
P0=DSY_CODE[shi2];
DelayMS(5);
P2=0x00;
P2=0x02;
P0=DSY_CODE[ch1];
DelayMS(5);
P2=0x00;
P2=0x01;
P0=DSY_CODE[ch2];
DelayMS(5);
P2=0x00;
}
}
void main()
{
TMOD=0x51;
EA=1;
ET0=1;
ET1=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0x00;
TL1=0x00;
TR0=1;
TR1=1;
while(1)
{
xianshi();
}
}
void zhongduan1() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
b++;
if(b==20)
{
c=(day*65536+TH1*256+TL1);
miao=c%100;
fen=(c/100)%100;
shi=(c/10000)%100;
ch=c/1000000;
b=0;
TH1=0;
TL1=0;
TR1=0;
}
}
void zhongduan2() interrupt 3
{
day++;
}
|