#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uint i,miao,fen,shi,fen1,fen2,fen3,fen4,shi1,shi2,shi3,shi4,flag1,flag2,flag3,flag4,flag5,aa,K1num,K2num,K3num,K4num,N,z;
uchar code table[]=" H.I.T CHiNA";
uchar code table2[]="
tiME ";
uchar code Al
ARM_0[]=" GBDS ";
uchar code Alarm_1[]=" SKDS ";
uchar code Alarm_2[]=" XKDS ";
uchar code Alarm_3[]=" DKDS ";
uchar code Alarm_00[]=" GB ";
uchar code Alarm_11[]=" SK ";
uchar code Alarm_22[]=" XK ";
uchar code Alarm_33[]=" DK ";
uchar code deng[]= " LIGHTING ";
sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
sbit K4=P1^3;
sbit rs=P2^0;
sbit rw=P2^1;
sbit lcden=P2^2;
sbit LED2=P2^3;
sbit LED=P2^4;
sbit beep=P2^5;
void delay (z)
{ uint x,y;
for(x=z;x>0;x--);
for(y=110;y>0;y--);
}
void write_com(uchar com)
{rs=0;
rw=0;
lcden=0;
P3=com;
delay(5);
lcden=1;
delay(5);
lcden=0; }
void write_date(uchar date)
{rs=1;
rw=0;
lcden=0;
P3=date;
delay(5);
lcden=1;
delay(5);
lcden=0; }
void write_sfm(uchar add,uchar date)
{uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);}
void init()
{uint num;
aa=0;
K1num=0;
K2num=0;
K3num=0;
K4num=0;
flag1=1;
flag2=1;
flag3=1;
flag4=1;
flag5=1;
LED=1;
LED2=0;
rw=0;
N=100;
miao=0;
fen=0;
shi=7;
fen1=6;
shi1=7;
fen2=8;
shi2=7;
fen3=10;
shi3=7;
fen4=12;
shi4=7;
beep=0;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table[num]);
delay(10);}
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80+0x40+15);
write_date(' ');
write_sfm(12,fen);
write_sfm(9,shi);
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1; }
void xianshi()
{write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(table2[i]);
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80+0x40+15);
write_date(' ');
write_sfm(12,fen);
write_sfm(9,shi);}
void time()
{
if((K1num==0)&&(flag3==1))
{write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(table2[i]);
if(K1==0)
{delay(5);
flag5=1;
if((K1==0)&&(K1num==0))
{K1num=1;
while(!K1)
if(K1num==1)
{TR0=0;
write_com(0x0f);
write_com(0x80+0x40+13);}}}
if((K1==0)&&(K1num==1))
{delay(5);
if(K1==0)
{write_com(0x80+0x40+10);
K1num=1;
while(!K1);
shi++;
if(shi==24)
shi=0;
write_sfm(9,shi);
write_com(0x80+0x40+10);}}
if((K2==0)&&(K1num==1))
{delay(5);
if(K2==0)
{write_com(0x80+0x40+13);
K1num=1;
while(!K2);
fen++;
if(fen==60)
fen=0;
write_sfm(12,fen);
write_com(0x80+0x40+13);}}
if(K1num==1)
{if(K3==0)
{delay(5);
if(K3==0)
{flag5=0;
K1num=0;
while(!K3);
write_com(0x0c);
TR0=1;
flag1=1;
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80+0x40+15);
write_date(' '); } } } }
void guangbo()
{if(K3num==0)
{write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_00[i]);}
if((K3==0)&&(K3num==0))
{delay(5);
if(K3==0)
{flag1=0;
write_com(0x80+0x40+13);
while(!K3);
K3num=1;
write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_0[i]);
write_sfm(12,fen);
write_sfm(9,shi);
write_com(0x80+0x40+13);
}}}
if((K2==0)&&(K3num==0))
{delay(5);
if(K2==0)
{write_sfm(12,fen1);
write_sfm(9,shi1);
while(!K2);
write_sfm(12,fen);
write_sfm(9,shi);
}}
if((K1==0)&&(K3num==1))
{delay(5);
if(K1==0)
{write_com(0x80+0x40+10);
K3num=1;
while(!K1);
shi++;
if(shi==24)
shi=0;
write_sfm(9,shi1);
write_com(0x80+0x40+10);
if((K2==0)&&(K1num==1))
{delay(5)
if(K2==0)
write_com(0x80+0x40+13);
K1num=1;
while(!K2);
fen++;
if(fen=60)
fen=0;
write_sfm(12,fen1);
write_com(0x80+0x40+13);
if(K1num==1)
{if(K3==0)
delay(5);
if(K3==0)
{flag5=0;
K1num=0;
while(!K3);
write_com(0x0c);
flag1=1;
write_sfm(12,fen);
write_sfm(9,shi);
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80=0x40+15);
write_date(' ');}}}}}
void shangke()
{if((K3num==0);
{write_come(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_11[i]);
if((K3==0)&&(K3num==0))
{delay(5);
if(K3==0)
{flag1=0;
write_com(0x80+0x40+13);
while(!K3);
K3num=1;
write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_1[i]);
write_sfm(12,fen2);
write_sfm(9,shi2);
write_com(0x0f);
write_com(0x80+0x40+13);
}}
if((K2==0)&&(K3num==0))
{delay(5);
if(K2==0)
{write_sfm(12,fen2);
write_sfm(9,shi2);
while(!K2);
write_sfm(12,fen);
write_sfm(9,shi);}}
if((K1==0)&&(K3num==1))
{delay(5);
if(K1==0)
{write_com(0x80+0x40+10);
K3num=1;
while(!K1);
shi++;
if(shi==24)
shi=0;
write_sfm(9,shi1);
write_com(0x80+0x40+10);
if((K2==0)&&(K1num==1))
{delay(5)
if(K2==0)
write_com(0x80+0x40+13);
K1num=1;
while(!K2);
fen++;
if(fen=60)
fen=0;
write_sfm(12,fen1);
write_com(0x80+0x40+13);
if(K1num==1)
{if(K3==0)
delay(5);
if(K3==0)
{flag5=0;
K1num=0;
while(!K3);
write_com(0x0c);
flag1=1;
write_sfm(12,fen);
write_sfm(9,shi);
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80=0x40+15);
write_date(' ');}}}
void xiake()
{if((K3num==0);
{write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_22[i]);
if((K3==0)&&(K3num==0))
{delay(5);
if(K3==0)
{flag1=0;
write_com(0x80+0x40+13);
while(!K3);
K3num=1;
write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_2[i]);
write_sfm(12,fen);
write_sfm(9,shi);
write_com(0x80+0x40+13);
}}}
if((K2==0)&&(K3num==0))
{delay(5);
if(K2==0)
{write_sfm(12,fen3);
write_sfm(9,shi3);
while(!K2);
write_sfm(12,fen);
write_sfm(9,shi);
}}
if((K1==0)&&(K3num==1))
{delay(5);
if(K1==0)
{write_com(0x80+0x40+10);
K3num=1;
while(!K1);
shi++;
if(shi==24)
shi=0;
write_sfm(9,shi1);
write_com(0x80+0x40+10);
if((K2==0)&&(K1num==1))
{delay(5)
if(K2==0)
write_com(0x80+0x40+13);
K1num=1;
while(!K2);
fen++;
if(fen=60)
fen=0;
write_sfm(12,fen1);
write_com(0x80+0x40+13);
if(K1num==1)
{if(K3==0)
delay(5);
if(K3==0)
{flag5=0;
K1num=0;
while(!K3);
write_com(0x0c);
flag1=1;
write_sfm(12,fen);
write_sfm(9,shi);
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80=0x40+15);
write_date(' ');}}}
void dengkong()
if((K3num==0);
{write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_00[i]);
if((K3==0)&&(K3num==0))
{delay(5);
if(K3==0)
{flag1=0;
write_com(0x80+0x40+13);
while(!K3);
K3num=1;
write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_0[i]);
write_sfm(12,fen);
write_sfm(9,shi);
write_com(0x80+0x40+13);
}}}
if((K2==0)&&(K3num==0))
{delay(5);
if(K2==0)
{write_sfm(12,fen1);
write_sfm(9,shi1);
}}
if((K1==0)&&(K3num==1))
{delay(5);
if(K1==0)
{write_com(0x80+0x40+10);
K3num=1;
while(!K1);
shi++;
if(shi==24)
shi=0;
write_sfm(9,shi1);
write_com(0x80+0x40+10);
if((K2==0)&&(K1num==1))
{delay(5)
if(K2==0)
write_com(0x80+0x40+13);
K1num=1;
while(!K2);
fen++;
if(fen=60)
fen=0;
write_sfm(12,fen1);
write_com(0x80+0x40+13);
if(K1num==1)
{if(K3==0)
delay(5);
if(K3==0)
{flag5=0;
K1num=0;
while(!K3);
write_com(0x0c);
flag1=1;
write_sfm(12,fen);
write_sfm(9,shi);
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80=0x40+15);
write_date(' ');}}}
void clock()
if((((fen==fen1)&&(shi==shi1))||((fen==fen2)&&(shi==shi2))||((fen==fen3)&&(shi==shi3))||((fen==fen4)&&(shi==shi4)))&&(flag2==1))
{beep=1;
flag5=0;flag0=0;
delay(100);
beep=0;
delay(100);
beep=1;
delay(100);
beep=0;
delay(100);
beep=1;
delay(100);
beep=0;
delay(300);}
else
{beep=0;}
if(((fen!=fen1)&&(fen!=fen2)&&(fen!=fen3)&&(fen!=fen4))&&(flag4=0)&&(flag5=0))
{xianshi();
if((fen==fen1)&&(shi==shi1&&(flag2==1))
{LED2=1;}
write_come(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_00[i]);
write_sfm(12,fen1);
write_sfm(9,shi1);
else
{LED2=0;}
if((((fen==fen1)&&(shi==shi1)&&(flag2==0))||((fen-1=fen1)&&(shi=shi1)))&&(flag4==0))
{xianshi();}
if((fen==fen2)&&(shi==shi2)&&(flag2==1))
write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_11[i]);
write_sfm(12,fen2);
write_sfm(9,shi2);}
if((((fen==fen2)&&(shi==shi2)&&(flag2==0))||((fen-1=fen2)&&(shi=shi2)))&&(flag4==0))
{xianshi()}
if((fen==fen3)&&(shi==shi3)&&(flag2==1))
write_com(0x80+0x40);
for(i=0;i<9;i++)
write_date(Alarm_22[i]);
write_sfm(12,fen3);
write_sfm(9,shi3);}
if((((fen==fen3)&&(shi==shi3)&&(flag2==0))||((fen-1=fen3)&&(shi=shi3)))&&(flag4==0))
{xianshi()}
if((fen==fen4)&&(shi==shi4)&&(flag2==1))
write_com(0x80+0x40);
for(i=0;i<15;i++)
write_date(Deng[i]);
if((((fen==fen4)&&(shi==shi4)&&(flag2==0))||((fen-1=fen4)&&(shi=shi4)))&&(flag4==0))
{xianshi()}
void main()
{init();
while(1)
{if((K4==0)&&(flag3==1)}
{delay(2000);
K4num++;
delay(100);
if(K4num==5)
K4num=0;
if((K4==0)&&(flag3==0))
delay(5)
if(K4==0)
{flag2=0;
flag3=1;
delay(300);}
if(K4num==0)
{time();
flag4=0;}
if(K4num==1)
{guangbo();
flag4=1;}
if(K4num==2)
{shangke();
flag4=1;
if(K4num==3)
{xiake();
flag4=1;}
if(K4num==4)
{ dengkong();
flag4=1;}
clock();}}
void time0()interrupt 1
{TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==20)
aa=0;
miao+=1;
if(miao==60)
miao=0;
fen+=1;
flag2=1;
if(fen==60)
fen=0;
shi+=1;
if(shi==24)
shi=0;
if(flag1==1)
{
write_sfm(9,shi);
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80+0x40+15);
write_date(' ');}}
if(flag1==1)
{write_sfm(12,fen);
write_com(0x80+0x40+11);
write_date(':');
write_com(0x80+0x40+14);
write_date(' ');
write_com(0x80+0x40+15);
write_date(' ');}}}}
void()定时加不进去,老是说有语法错误,求指点,在void guangbo()处
一周热门 更多>