#include<reg52.h>
void delay1ms(void);
void yanshi(ms);
void delay(unsigned int cnt);
void labaxiang();
#define uint unsigned int
#define uchar unsigned char
#define liangdu 1
uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
sbit hahaha=P1^3;
sbit beep=P1^3;
sbit d1=P1^0;
sbit d2=P1^7;
sbit key1=P3^2;
sbit key2=P3^3;
sbit key3=P2^3;
sbit key4=P2^2;
sbit LED1=P3^7;
sbit LED2=P3^6;
sbit LED3=P3^5;
sbit LED4=P3^4;
uchar temp,aa,miaos,miaog,qian,bai,shi,ge,fen,sh,bb,mh;
void display(uchar qian,uchar bai,uchar shi,uchar ge);
void init();
void delay(uint z);
void main(void)
{
init();
mh=1;
while(1)
{
labaxiang();
if(key1==0)
{
delay(200);
while(key1==0);
fen++;
if(fen==59)
{
fen=0;
}
}
if(key2==0)
{
delay(200);
while(key2==0);
if(fen!=0)
{
fen--;
}
if(fen==0)
{
fen=59;
}
}
if(key3==0)
{
delay(200);
while(key3==0);
sh++;
if(sh==23)
{
sh=0;
}
}
if(key4==0)
{
delay(200);
while(key4==0);
if(sh!=0)
{
sh--;
}
if(sh==0)
{
sh=23;
}
}
if(aa==20)
{
bb++;
aa=0;
miaog=bb%10;
miaos=bb/10%6;
mh=~mh;
}
if(bb==60)
{
fen++;
bb=0;
}
ge=fen%10;
shi=fen/10%6;
if(fen==60)
{ sh++;
fen=0;
fen=0;
}
bai=sh%10;
qian=sh/10;
if(bai==10)
bai=0;
if(qian==2)
{
if(bai==4)
{
qian=0;
bai=0;
}
}
if(sh==24)
{
sh=0;
}
display(qian,bai,shi,ge);
}
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
LED1=1;
P0=table[qian];
LED1=0;
delay(liangdu);
LED1=1;
LED2=1;
P0=table[bai];
LED2=0;
delay(liangdu);
LED2=1;
LED2=1;
if(mh==1)
{
P0=0x7F;
}
else P0=0xFF;
LED2=0;
delay(3);
LED2=1;
LED3=1;
P0=table[shi];
LED3=0;
delay(liangdu);
LED3=1;
LED4=1;
P0=table[ge];
LED4=0;
delay(liangdu);
LED4=1;
}
void init()
{
d1=1;
d2=1;
fen=0;
sh=0;
temp=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
void delay(uint z)
{
unsigned char a,b;
for(b=102;b>0;b--)
for(a=3;a>0;a--);
}
void labaxiang()
{
int i;
for(i=0;i<200;i++)//喇叭发声的时间循环,改变大小可以改变发声时间长短
{
delay(80);//参数决定发声的频率,估算值
hahaha=!hahaha;
}
hahaha=1; //喇叭停止工作,间歇的时间,可更改{
yanshi(1000);
}
void yanshi(ms)
{
int i;
for(i=0;i<ms;i++)
delay1ms();
}
void delay1ms(void) //误差 -0.651041666667us
{
unsigned char a,b;
for(b=102;b>0;b--)
for(a=3;a>0;a--);
}
|