编程高手的进!!!
- 提问者网友:献世佛
- 2021-07-20 15:21
- 五星知识达人网友:野味小生
- 2021-07-20 16:26
这有什么难的,
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar j,second,minute,hour;
uchar sec2,sec1,min1,min2,hou1,hou2;
void delay(uint z);
void init();
void display();
void main()
{
init();
while(1)
{
display();
}
}
void delay(uint z)
{
uint x,y;
for(x=0;x<z;x++)
for(y=0;y<5;y++);
}
void zd() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
j++;
if(j==20)
{
j=0;
second--;
if(second==0)
{
second=59;
minute--;
if(minute==0)
{
minute=59;
hour--;
if(hour==0)
hour=23;
minute=59;
second=59;
}
}
}
}
void init()
{
second=59;
minute=59;
hour=23;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void display()
{
sec2=second/10;
sec1=second%10;
P2=0x7f;
P0=table[sec1];
delay(10);
P2=0xff;
P2=0xbf;
P0=table[sec2];
delay(10);
P2=0xff;
min2=minute/10;
min1=minute%10;
P2=0xef;
P0=table[min1];
delay(10);
P2=0xff;
P2=0xf7;
P0=table[min2];
delay(10);
P2=0xff;
hou2=hour/10;
hou1=hour%10;
P2=0xfd;
P0=table[hou1];
delay(10);
P2=0xff;
P2=0xfe;
P0=table[hou2];
delay(10);
P2=0xff;
P2=0xdf;
P0=0xbf;
delay(10);
P2=0xff;
P2=0xfb;
P0=0xbf;
delay(10);
P2=0xff;
}