#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar aa,num1,s,h2,h1,m1,m2;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uchar ,uchar ,uchar,uchar);
void delay(uint z)
{
uint t1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
void main()
{
m1=0;
h2=0;
h1=0;
m2=0;
P2=0x0f;
s=0;
aa=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display ( h2,h1,m2, m1);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==1)
{
aa=0;
s=s+1;
if(s==1)
{ s=0;
m1++;
if(m1==10)
{ m1=0;
m2=m2+1;
if(m2==6)
{ m2=0;
h1=h1+1;
if(h1==10)
{ h1=0;
h2=h2+1;
while(h2==2)
{ h1=0;
if(h1==5)
{ m1=0;m2=0;h1=0;h2=0;
}
}
}
}
}
}
}
}
void display(uchar num1,uchar m2,uchar h1,uchar h2)
{
P2=0xef;
P0=table[num1];
delay(2) ;
P2=0xdf;
P0=table[m2];
delay(2) ;
P2=0xbf;
P0=table[h1];
delay(2);
P2=0x7f;
P0=table[h2];
delay(2);
}
特别是下面的语句好像没用
while(h2==2)
{ h1=0;
if(h1==5)
{ m1=0;m2=0;h1=0;h2=0; |