#include <reg52.h>
#define uint unsigned int
#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};
uchar code tablewe[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uint minute,i,j;
uint second,hour;
uint ms20;
uchar a,b,c,d,e,f,g;
void display();
void delay1ms();
void inti();
void main()
{
inti();
while(1)
{
if(ms20==500)
{
ms20=0;
second++;
if(second==60)
{
second=0;
}
a=second%10;
b=second/10;
if(b==6)
{
minute++;
if(minute==60)
{
second=0;
minute=0;
}
c=minute%10;
d=minute/10;
}
if(d==6)
{
hour++;
if(hour==24)
{
second=0;
minute=0;
hour=0;
}
e=hour%10;
f=hour/10;
}
}
display();
}
}
void inti()
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
}
void t0() interrupt 1
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
ms20++;
}
void display()
{
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[a];
dula=0;
delay1ms();
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table[b];
dula=0;
delay1ms();
wela=1;
P0=0xfb;
wela=0;
dula=1;
P0=table[c];
dula=0;
delay1ms();
wela=1;
P0=0xf7;
wela=0;
dula=1;
P0=table[d];
dula=0;
delay1ms();
wela=1;
P0=0xef;
wela=0;
dula=1;
P0=table[e];
dula=0;
delay1ms();
wela=1;
P0=0xdf;
wela=0;
dula=1;
P0=table[f];
dula=0;
delay1ms();
}
void delay1ms()
{
for(i=0;i<50;i++)
for(j=0;j<50;j++);
}
24小时计时的程序,哪有问题啊?大神们赐解,,,,,啊!!!! |