#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wei=P2^7;
sbit duan=P2^6;
sbit x0=P3^4;
sbit x1=P3^5;
sbit x2=P3^6;
sbit x3=P3^7;
sbit bz=P2^3;
sbit led=P1^0;
uchar hs,h,ms,m,ss,s,hour,min,sec,t1,t2,tt;
uint t0;
void smgxs(uchar,uchar,uchar,uchar,uchar,uchar);
uchar code table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,
0x79,0x71
};
void keyscan();
void xsxz();
void init ();
void delay2();
void laozhong ();
void delay(uchar);
void main()
{
x0=1;
tt=1;
init();
while(1)
{
xsxz();//显示选择
delay2();
smgxs(hs,h,ms,m,ss,s);
keyscan();
laozhong();
}
}
void init ()
{
EA=1;
ET0=1;
TMOD=0X02;
TR0=1;
TH0=0xa3;
}
void smgxs(uchar hs,uchar h,uchar ms,uchar m,uchar ss,uchar s)
{
duan=1;
P0=table[hs];
duan=0;
P0=0xff;
wei=1;
P0=0xfe;
wei=0;
delay(10);
duan=1;
P0=table[h];
duan=0;
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
delay(10);
duan=1;
P0=table[ms];
duan=0;
P0=0xff;
wei=1;
P0=0xfb;
wei=0;
delay(10);
duan=1;
P0=table[m];
duan=0;
P0=0xff;
wei=1;
P0=0xf7;
wei=0;
delay(10);
duan=1;
P0=table[ss];
duan=0;
P0=0xff;
wei=1;
P0=0xef;
wei=0;
delay(10);
duan=1;
P0=table[s];
duan=0;
P0=0xff;
wei=1;
P0=0xdf;
wei=0;
delay(10);
}
void delay2 ()
{
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void xsxz()//显示选择
{
if(tt==0)
{
hs=t1/10;
h=t1%10;
ms=t2/10;
m=t2%10;
ss=0;
s=0;
}
else
{
hs=hour/10;
h=hour%10;
ms=min/10;
m=min%10;
ss=sec/10;
s=sec%10;
}
}
void keyscan()
{
if(x0==0)
{
delay(10);
if(x0==0)
{
tt=!tt;
}
while(!x0);
}
if(tt==0)
{
if(x1==0)
{
delay(20);
if(x1==0)
{
t1++;
if(t1==24)
{
t1=0;
}
while(!x1);
}
}
}
if(x2==0&tt==0)
{
delay(20);
if(x2==0)
{
t2++;
if(t2==60)
{
t2=0;
}
}
while(!x2);
}
if(tt==1)
{
if(x1==0)
{
delay(10);
if(x1==0)
{
hour++;
if(hour==24)
{
hour=0;
}
while(!x1);
}
}
if(x2==0&tt==1)
{
delay(20);
if(x2==0)
{
min++;
if(min==60)
{
min=0;
}
while(!x2);
}
}
}
}
void laozhong ()
{
if(x3==0)
{
delay(10);
if(x3==0)
{
led=!led;
}
}
while(!x3);
if(hour==t1&min==t2)
{
if(led==0)
{
bz=0;
}
else
{
bz=1;
}
}
}
void timer0() interrupt 1
{
t0++;
if(t0==10000)
{
t0=0;
sec++;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>