#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={"TIME0"};
uchar code table1[]={"GET UP TIME!0"};
uchar code table2[]={"MON0TUE0WED0THU0FRI0SAT0SUN0"};
uchar data buf[]={5,2,11,4,12,0,0};
uchar data buf1[]={7,0};
sbit enable=P3^4;
sbit rs=P3^5;
sbit rw=P3^7;
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
sbit k5=P3^6;
sbit P0_0=P0^0;
sbit P0_1=P0^1;
sbit P1_7=P1^7;
sbit P2_7=P2^7;
uchar temp,num,num1,hi,li,kk;
uchar a=10,b,c,disp_var,ww,ee;
uchar *table_var,(*fun)( );
uchar miao,day,key_var,address;
unsigned long lamp_var;
bit bdata nao,flash_var;
void initial (void);
void cls (void);
void busy (void);
void write (void);
void writedata (void);
void delay (uchar m);
//void year_disp(void);
void string_disp(void);
void week_disp(void);
void time_disp(void);
void display(void);
void seenao_time(void);
void nao_display(void);
void adjust_nao(void);
void adjust_nao_key(void);
void adjust_nao_key1(void);
void nao_disp(void);
void datetime_adjust(void);
void adjust_year_key(void);
void adjust_mon_key(void);
void write_kong (void);
void adjust_day_key(void);
void flash (uchar job);
void flash2 (void);
void adjust_week_key(void);
void adjust_time1_key(void);
void adjust_time2_key(void);
void datetime_adjust(void) //年月日,星期,时间总调整程序
{
time_disp();
while(1)
{
switch(key_var)
{
case 1:
{(*fun)=adjust_year_key;
address=0x82;
flash (1);}
break;
case 2:
{(*fun)=adjust_mon_key;
address=0x85;
flash (2);}
break;
case 3:
{(*fun)=adjust_day_key;
address=0x88;
flash (3);
year_disp();}
break;
case 4:
{flash2 ();
week_disp();}
break;
case 5:
{(*fun)=adjust_time1_key;
address=0xc5;
flash (4);}
break;
case 6:
{(*fun)=adjust_time2_key;
address=0xc8;
flash (5);
time_disp();}
break;
default:break;
}
if(k4==0){goto lable2;}
}
lable2:
{a=10;
lamp_var=69999;
TL0=183;
TH0=60;
TR0=1;
display();} //GOTO跳出调整
}
void flash (uchar job) //年月日,时间闪动
{
for(ww=8;ww>0;ww--)
{for(ee=188;ee>0;ee--);
{if(job<=3) {year_disp();}
if((job>=4)&&(job<=6)) {time_disp();}
if((job>=7)&&(job<=8)) {nao_display();}
(*fun)();
if(k3==0)
{do
{;}
while(k3==0);
{key_var++;
if((key_var>6)&&(flash_var==0)) {key_var=1;}
if((key_var>8)&&(flash_var==1)) {key_var=7;}
break;
}
}
if(k4==0){goto lable;}
}
}
for(ww=12;ww>0;ww--)
{for(ee=218;ee>0;ee--);
{
disp_var=address;
write_kong ();
(*fun)();
}
}
lable:{;}
}
void flash2 (void) //星期 闪动
{
for(ww=11;ww>0;ww--)
{for(ee=188;ee>0;ee--);
{week_disp();
adjust_week_key();
if(k3==0)
{do
{week_disp();}
while(k3==0);
{key_var++;break;}
}
if(k4==0){goto lable1;}
}
}
for(ww=11;ww>0;ww--)
{for(ee=188;ee>0;ee--);
{disp_var=0x8c;
write_kong ();
disp_var++;
temp=disp_var;
write();
temp=' ';
writedata();
adjust_week_key();
}
}
lable1:{;}
}
void adjust_year_key(void) // year ++;--
{
while(k1==0)
{buf[0]++;
if(buf[0]==16){buf[0]=5;}
year_disp();
delay(199);}
while(k2==0)
{if(buf[0]==5){buf[0]=16;}
buf[0]--;
year_disp();
delay(199);}
}
void adjust_mon_key(void) // mon ++;--
{
while(k1==0)
{buf[1]++;
if(buf[1]==13){buf[1]=1;}
year_disp();
delay(199);}
while(k2==0)
{if(buf[1]==1){buf[1]=13;}
buf[1]--;
year_disp();
delay(199);}
}
void adjust_day_key(void) // day ++;--
{
while(k1==0)
{buf[2]++;
if(buf[2]==32){buf[2]=1;}
year_disp();
delay(128);}
while(k2==0)
{if(buf[2]==1){buf[2]=32;}
buf[2]--;
year_disp();
delay(128);}
}
void write_kong (void) // 写入空字符
{
temp=disp_var;
write();
temp=' ';
writedata();
disp_var++;
temp=' ';
writedata();
}
void adjust_time1_key(void) // HH ++;--
{
while(k1==0)
{buf[4]++;
if(buf[4]==24){buf[4]=0;}
time_disp();
delay(128);}
while(k2==0)
{if(buf[4]==0){buf[4]=24;}
buf[4]--;
time_disp();
delay(128);}
}
void adjust_time2_key(void) // MM ++;--
{
while(k1==0)
{buf[5]++;
if(buf[5]==60){buf[5]=0;}
time_disp();
delay(128);}
while(k2==0)
{if(buf[5]==0){buf[5]=60;}
buf[5]--;
time_disp();
delay(128);}
}
void adjust_week_key(void) // WEEK ++;--
{
while(k1==0)
{buf[3]++;
if(buf[3]==7){buf[3]=0;}
week_disp();
delay(228);}
while(k2==0)
{if(buf[3]==0){buf[3]=7;}
buf[3]--;
week_disp();
delay(228);}
}
void seenao_time(void) //闹铃时间查询,6秒后自动返回
{
uint x;
uchar y,z,un=0;
cls ();
disp_var=0x80;
table_var=&table1[0];
string_disp();
nao_display();
for(x=1119;x>0;x--)
{for(y=219;y>0;y--);
{for(z=219;z>0;z--);
{
if(k3==0) //K3按下调时间,否则6秒后退出
{ do
{;}
while(k3==0);
{key_var=7;
flash_var=1;
adjust_nao();
goto lable2;
}
}
}
}
}
lable2:
{cls ();
display();
lamp_var=66666;
key_var=1;}
}
void adjust_nao(void) //闹铃调整
{
while(1)
{
switch(key_var)
{
case 7:
{(*fun)=adjust_nao_key;
address=0xc5;
flash(7);}
break;
case 8:
{(*fun)=adjust_nao_key1;
address=0xc8;
flash(8);}
break;
default: break;
}
if(k4==0){goto lable3;}
}
lable3:return;
}
void adjust_nao_key(void) //闹铃hh++;--
{
while(k1==0)
{buf1[0]++;
if(buf1[0]==24){buf1[0]=0;}
nao_display();
delay(199);}
while(k2==0)
{if(buf1[0]==0){buf1[0]=24;}
buf1[0]--;
nao_display();
delay(199);}
}
void adjust_nao_key1(void) //闹铃mm++;--
{
while(k1==0)
{buf1[1]++;
if(buf1[1]==60){buf1[1]=0;}
nao_display();
delay(159);}
while(k2==0)
{if(buf1[1]==0){buf1[1]=60;}
buf1[1]--;
nao_display();
delay(159);}
}
void nao_display(void) //闹铃时间扫描显示
{
disp_var=0xc5;
temp=disp_var;
write();
temp=((buf1[0]/10)+0x30);
writedata();
disp_var++;
temp=((buf1[0]%10)+0x30);
writedata();
disp_var++;
temp=disp_var;
write();
temp=':';
writedata();
disp_var++;
temp=disp_var;
write();
temp=((buf1[1]/10)+0x30);
writedata();
disp_var++;
temp=((buf1[1]%10)+0x30);
writedata();
}
void display(void) //全显示程序
{
year_disp(); //年月日函数
week_disp(); //星期扫描函数
disp_var=0xc0; //TIME字符扫描
table_var=&table[0]; //指针赋值
string_disp(); //字符串函数
time_disp(); //时间扫描函数
nao_disp(); //闹铃符号显示函数
}
void nao_disp(void) //闹铃符号显示函数
{
if(nao==1)
{temp=0xce;
write();
temp=0x40;
writedata(); }
if(nao==0)
{temp=0xce;
write();
temp=0x20;
writedata(); }
}
void year_disp(void) //年月日函数
{
num=0;
kk=0;
temp=0x80; //显示年的高位20;
write();
temp=0x32;
writedata();
temp=0x81;
write();
temp=0x30;
writedata();
disp_var=0x82; //显示年月日;
while(num<3)
{
temp=disp_var;
write();
hi=((buf[num]/10)+0x30);
li=((buf[num]%10)+0x30);
temp=hi;
writedata();
disp_var++;
temp=li;
writedata();
disp_var++;
temp=disp_var;
if(kk!=2){write();temp='/';writedata();}
num++;
kk++;
disp_var++;
}
}
void week_disp(void) //星期扫描
{
disp_var=0x8c;
table_var=&table2[(buf[3]*4)];
string_disp();
}
void string_disp(void) //字符串扫描
{
do
{temp=disp_var;
write();
temp=*table_var;
writedata();
disp_var++;
table_var++;}
while(*table_var!=0x30);
}
void time_disp(void) //时间扫描
{
disp_var=0xc5;
num=4;
kk=0;
while(num!=7)
{
temp=disp_var;
write();
hi=((buf[num]/10)+0x30);
li=((buf[num]%10)+0x30);
temp=hi;
writedata();
disp_var++;
temp=li;
writedata();
disp_var++;
temp=disp_var;
if(kk<2){write();temp=':';writedata();}
num++;
kk++;
disp_var++;
}
}
void initial (void) //LCD初始化
{
temp=0x38; //#00111000b
write();
temp=0x0c; //#00001100b
write();
temp=0x06; //#00000110b
write();
}
void cls (void) //清屏
{
temp=0x01;
enable=0;
write();
}
void write (void) //写资料寄存器
{
busy();
enable=0;
rw=0;
rs=0;
enable=1;
P1=temp;
enable=0;
}
void writedata (void) //写数据
{
busy();
enable=0;
rw=0;
rs=1;
enable=1;
P1=temp;
enable=0;
}
void busy (void) //忙查询
{
uchar busy_temp;
enable=0;
do
{rw=1;
rs=0;
enable=1;
busy_temp=P1_7;
enable=0;}
while(busy_temp==1);
delay(6);
}
void delay (uchar m) //延时
{
uchar n;
for(;m>0;m--)
for(n=100;n>0;n--);
}
void intermit() interrupt 1 using 0 //中断服务程序
{
EA=0;
TR0=0;
TL0+=183;
TH0+=60;
a--;
if(a==0)
{a=10; P0_0=!P0_0; b++;}
if(b==2)
{b=0;buf[6]++;}
if(buf[6]==60)
{buf[6]=0;buf[5]++;}
if(buf[5]==60)
{buf[5]=0; buf[4]++;}
if(buf[4]==24)
{buf[4]=0; buf[3]++; buf[2]++;}
if(buf[3]==7)
{buf[3]=0;}
if(buf[2]==32)
{buf[2]=1; buf[1]++;}
if(buf[1]==13)
{buf[1]=1; buf[0]++;}
if(buf[0]==16)
{buf[7]=(05,02,11,1,12,00,00);}
if(nao==1)
{if(buf1[0]==buf[4])
{ if(buf1[1]==buf[5]) { P2_7=0; } }
}
EA=1;
TR0=1;
}
void main(void) //主程序
{
TMOD=1;
EA=1;
ET0=1;
TL0=0xb0;
TH0=0x3c;
TR0=1;
P0_0=0;
initial();
cls();
display();
miao=buf[6];
day=buf[3];
while(1)
{
if(miao!=buf[6]) //比较旧秒与新秒之间有无变化,如有则扫描
{miao=buf[6];time_disp();}
if(day!=buf[3]) //比较旧日期与新日期之间有无变化,如有则扫描
{miao=buf[3];display();}
if(k1==0) //闹铃时间查询与调整
{P0_1=0;seenao_time();}
if(k2==0) //闹铃开 / 关
{do
{;}
while(k2==0);
{P0_1=0;
lamp_var=69999;
nao=!nao;
nao_disp();}
}
if(k3==0) //总调整(年月日,星期,时间)
{TR0=0;
miao=buf[6]=0;
P0_1=0;
key_var=1;
flash_var=0;
datetime_adjust();}
if(k5==0){P0_1=0;lamp_var=69999;} //背光开关
lamp_var--; //延时6秒关背光
if(lamp_var==1) {P0_1=1;}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>