基于51单片机的电子万年历毕业论文设计 下载本文

else play16(48, 0, guan);

play32_num(32, 2, alarm.hour); play32(64, 2, 10);

play32_num(80, 2, alarm.min);

play16(0, 6, zheng); play16(16, 6, dian); play16(32, 6, bao); play16(48, 6, shi); play16(64, 6, maohao); if (Clock_flag) play16(80, 6, kai); else play16(80, 6, guan);

for (t=0; t<30000; t++) { key_val = scan_key(); if (key_val > 1) break; else if (key_val == 1) { if (Alarm_flag) play16(48, 0|0x80, kai); else play16(48, 0|0x80, guan); while (1) { key_val = scan_key(); if (key_val == 1) // 完成设置 { if (state >= 4) state = 0; else state++; if (Alarm_flag) play16(48, 0, kai); else play16(48, 0, guan); play32_num(32, 2, alarm.hour); play32_num(80, 2, alarm.min);

11

if (Clock_flag) play16(80, 6, kai); else play16(80, 6, guan);

switch (state) { case 1: if (Alarm_flag) play16(48, 0|0x80, kai); else play16(48, 0|0x80, guan); break; case 2: play32_num(80, 2|0x80, alarm.min); break; case 3: play32_num(32, 2|0x80, alarm.hour); break; case 4: if (Clock_flag) play16(80, 6|0x80, kai); else play16(80, 6|0x80, guan); break; default: break; } }

else if (key_val > 1) { if (state == 1) { Alarm_flag = ~Alarm_flag; if (Alarm_flag) play16(48, 0|0x80, kai); else play16(48, 0|0x80, guan); } else if (state == 2) { if (key_val == 3) alarm.min++; else alarm.min--; if (alarm.min >= 60)

12

alarm.min = 0; else if (alarm.min < 0) alarm.min = 59; play32_num(80, 2|0x80, alarm.min); } else if (state == 3) { if (key_val == 3) alarm.hour++; else alarm.hour--; if (alarm.hour >= 24) alarm.hour = 0; else if (alarm.hour < 0) alarm.hour = 23; play32_num(32, 2|0x80, alarm.hour); } else if (state == 4) { Clock_flag = ~Clock_flag; if (Clock_flag) play16(80, 6|0x80, kai); else play16(80, 6|0x80, guan); } else { break; } } if (state == 0) break; } if (state == 0) break; } } }

main() { uint8 key_val;

read_18B20(); //读温度

13

Delay_nms(1000);//延时1S,等待18B20工作正常 LCD_init(); //初始化液晶 clear12864(); //清屏幕 main_frame(); //显示主界面框架 main_show(1); //刷新1次

read_18B20(); //读温度 play8_num(104, 6,zhengshu); //显示温度 while(1) { key_val = scan_key(); if (key_val == 1) //K1? { main_set(); } else if (key_val == 2) //K2? { clear12864(); //清屏幕 alarm_show(); clear12864(); //清屏幕 main_show(1); } else if (key_val == 3) //K3? { clear12864(); //清屏幕 alarm_show(); clear12864(); //清屏幕 main_show(1); } else { read_time((uint8 *)&time); main_show(0); if((time.sec%2)==0){read_18B20();} //每隔2S采集一次 } // 闹钟 if (Alarm_flag) { if ((flag == 0) && (alarm.hour == time.hour) && (alarm.min == time.min)) {

14