if(K2==0) {
delay(5); if(K2==0) { set--; while(!K2); if(set==-1)set=12; } }
DS1302_SetTime(0x88, set); break;
} case 7: { if(K1==0) {
delay(5); if(K1==0) { set++; while(!K1); if(set==100)set=0; } }
if(K2==0) {
delay(5); if(K2==0) { set--; while(!K2); if(set==-1)set=99; } }
DS1302_SetTime(0x8c, set); break; }
default: break;
} } else
21
//设置月//设置年
flag4=0; }
/*******设置温度的键盘扫描函数******/ void key_lcd() {
if(flag1==1&&k==3) //k一定不能掉,不然会在其他菜单里出现乱码 {
if(K3==0) //按键判断,选择设置温度的光标 { delay(5); if(K3==0) { while(!K3); flag++; //按键标识位 if(flag==5)flag=1; } }
switch(flag) { case 1: { if(K1==0) { delay(5); if(K1==0) { th1++; while(!K1); if(th1==10)th1=0; } } if(K2==0) { delay(5); if(K2==0) { th1--; while(!K2); if(th1==-1)th1=9; } }
22
LCD_pos(0x43); write_dat(th1+0x30); }break; case 2: {
if(K1==0) { delay(5); if(K1==0) { th2++; while(!K1); if(th2==10)th2=0; } } if(K2==0) { delay(5); if(K2==0) { th2--; while(!K2); if(th2==-1)th2=9; } }
LCD_pos(0x44);//位置设定 write_dat(th2+0x30); }break; case 3: {
if(K1==0) { delay(5); if(K1==0) { th3++; while(!K1); if(th3==10)th3=0; } } if(K2==0) { delay(5); if(K2==0)
23
{ th3--; while(!K2); if(th3==-1)th3=9; } } LCD_pos(0x4c); write_dat(th3+0x30); }break; case 4: { if(K1==0) { delay(5); if(K1==0) { th4++; while(!K1); if(th4==10)th4=0; } } if(K2==0) { delay(5); if(K2==0) { th4--; while(!K2); if(th4==-1)th4=9; } } LCD_pos(0x4d); write_dat(th4+0x30); }break; default:break; } }
else flag1=0; //m一定不能掉,否则在调节温度的时候会影响其他菜单 th=th1*10+th2; //获取设置温度的高位 tl=th3*10+th4; //获取设置温度的低位 }
void alarm_beep() //报警系统与当前温度进行比较并处理 {
24
if(temp>(th*10)||temp<(tl*10)) { beep=~beep; L1=0; adder++; tab=temp/10; write_add(adder,tab); } else { beep=1; L1=1; } }
/*****主函数*******/ void main() { init_18b20(); init_lcd(); init_2402(); beep=1; // Set_RTC(); count=7; while(1) { k=key4(); get_ds1302(&realtime);//取时间 temp=read_temp(); //取温度 delay(200); //延时 保持数据稳定 避免数据刷新 switch(k) { case 1: //菜单一,显示时间并且可以设置时间 { //key_time(); //get_ds1302(&realtime); LCD_pos(0); print(\ Time: \ print(realtime.TimeString); LCD_pos(0x40); print(\ Date: \ print(realtime.DateString);
25