void main() { U16 i, j, testnum; EA = 0; Timer0_Init(); //定时器0初始化 Data_Init(); Initial_DS1302(); EA = 1; L1602_init(); L1602_string(1,1," hechao "); L1602_string(2,1,"200820103208"); //延时 for (i=0;i<1000;i++) for (j=0;j<1000;j++) {;} //清屏 L1602_string(1,1," T C"); L1602_string(2,1," H %"); while(1) { //查询报警信号 //FlagSet=0为报警状态, //FlagSet=1为关报警状态, //FlagSet=2,3,4,5,6,7依次为设置年,月,日,时,分,秒状态 if ((FlagSet==1)&&(FlagAlert==0)&&(In_Alert==1)) //触发报警则存入报警时间 { SaveAlert(); FlagAlert=1; Beep=0; Led_Alert = 0; } if ((FlagSet==1)&&(In_Alert==1)) { Beep=0; Led_Alert = 0; } else //报警未打开或者无警可报 { FlagAlert=0; Beep=1; Led_Alert = 1; } if (FlagStartRH == 1) { //温湿度转换标志检查 TR0 = 0; testnum = RH(); FlagStartRH = 0; TR0 = 1; //读出温湿度,只取整数部分 humidity = U8RH_data_H; temperature = U8T_data_H; //读出日期时间值 DS1302_GetTime(&CurrentTime); year = CurrentTime.Year; month =CurrentTime.Month; day = CurrentTime.Day; hour = CurrentTime.Hour; minute = CurrentTime.Minute; second = CurrentTime.Second; DateToStr(&CurrentTime); TimeToStr(&CurrentTime); //如果不处于查询状态则显示当前日期时间温度湿度 if (FlagReview==0) { //清屏 L1602_string(1,1," T C"); L1602_string(2,1," "); L1602_string(2,12,"H %"); //显示温湿度 if (temperature<0) { L1602_string(2,7,"-"); } temperature = abs(temperature); int2str(temperature,str1); L1602_string(1,14,str1); int2str(humidity,str1); L1602_string(2,14,str1); L1602_string(1,1,CurrentTime.DateString); L1602_string(2,1,CurrentTime.TimeString); //产生时间设定时的闪烁效果,只在未查询且闪烁标志置位时运行 if (hide==1) { switch (FlagSet) { case 0: case 1: break; case 2: //年 L1602_string(1,1," "); break; case 3: //月 L1602_string(1,4," "); break; case 4: //日 L1602_string(1,7," "); break; case 5: //时 L1602_string(2,1," "); break; case 6: //分 L1602_string(2,4," "); break; case 7: //秒 L1602_string(2,7," "); break; default: break; } } } } //以下为键盘查询,当有按键从按下到弹起时,该按键被响应。 if ((Key_Up)&&(keyUp==0)){FlagKeyPress = 1; keyvalue = 1;} else if ((Key_Down)&&(keyDown==0)) {FlagKeyPress = 1; keyvalue = 2;} else if ((Key_Set)&&(keySet==0)){FlagKeyPress = 1; keyvalue = 3;} else if ((Key_Review)&&(keyReview==0)) {FlagKeyPress = 1; keyvalue = 4;} if (FlagKeyPress == 1) { KeyProcess(keyvalue); FlagKeyPress = 0; } if (!Key_Up) keyUp= 0; else keyUp = 1; if (!Key_Down)keyDown = 0; else keyDown = 1; if (!Key_Set) keySet= 0; else keySet = 1; if (!Key_Review) keyReview = 0; else keyReview = 1; Delay1ms(100); } }
|