#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp,min,hh,a;
uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar code table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
uchar code wei[]={0xff,0xef,0xdf,0xbf,0x7f,0x0f};
void delay(uchar z);
void main()
{
hh=0;
temp=0;
min=0;
TMOD=0x01;
EA=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
while(1)
{
if(a==19)
{a=0;
temp++;
if(temp==60)
{
temp=0;
min++;
if(min==60)
{
min=0;
hh++;
if(hh==24)
hh=0;
}
}
}
P2=table[min/10];
P1=wei[1];
delay(5);
P2=table1[min%10];
P1=wei[2];
delay(5);
P2=table[temp/10];
P1=wei[3];
delay(5);
P2=table[temp%10];
P1=wei[4];
delay(5);
}
}
void delay(uchar z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
}
完整程序
#define uchar unsigned char
#define uint unsigned int
uchar temp,min,hh,a;
uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar code table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};
uchar code wei[]={0xff,0xef,0xdf,0xbf,0x7f,0x0f};
void delay(uchar z);
void main()
{
hh=0;
temp=0;
min=0;
TMOD=0x01;
EA=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
while(1)
{
if(a==19)
{a=0;
temp++;
if(temp==60)
{
temp=0;
min++;
if(min==60)
{
min=0;
hh++;
if(hh==24)
hh=0;
}
}
}
P2=table[min/10];
P1=wei[1];
delay(5);
P2=table1[min%10];
P1=wei[2];
delay(5);
P2=table[temp/10];
P1=wei[3];
delay(5);
P2=table[temp%10];
P1=wei[4];
delay(5);
}
}
void delay(uchar z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
}
完整程序