马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar fs,fg,ms,mg,ss,sg,s,f,m,i,j,k;
sbit dula=P2^6;
sbit wela=P2^7;
void delay();
void display();
void main()
{
EA=1;
TMOD=0x01;
ET0=1;
TR0=1;
f=19;
m=0;
s=18;
while(1)
{
fs=f/10;
fg=f%10;
ms=m/10;
mg=m%10;
ss=s/10;
sg=s%10;
display();
}
}
void timer0()interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
k++;
if(k%200==0)
m++;
if(m==60)
{
m=0;
f++;
if(f==60)
{
f=0;
s++;
if(s==24)
s=0;
}
}
}
void display()
{
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[ss];
dula=0;
delay();
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table[sg];
dula=0;
delay();
wela=1;
P0=0xfb;
wela=0;
dula=1;
if(m%2==0)
P0=0x09;
else
P0=0;
dula=0;
delay();
wela=1;
P0=0xf7;
wela=0;
dula=1;
P0=table[fs];
dula=0;
delay();
wela=1;
P0=0xef;
wela=0;
dula=1;
P0=table[fg];
dula=0;
delay();
wela=1;
P0=0xdf;
wela=0;
dula=1;
if(m%2==0)
P0=0x09;
else
P0=0;
dula=0;
delay();
wela=1;
P0=0xbf;
wela=0;
dula=1;
P0=table[ms];
dula=0;
delay();
wela=1;
P0=0x7f;
wela=0;
dula=1;
P0=table[mg];
dula=0;
delay();
}
void delay()
{
for(i=0;i<30;i++)
for(j=0;j<20;j++);
} |