原理圖.png (46.92 KB, 下載次數(shù): 19)
下載附件
2018-4-14 14:25 上傳
void main(){ U16 i, j, testnum; EA = 0; Timer0_Init(); //定時(shí)器0初始化 Data_Init(); Initial_DS1302(); EA = 1; L1602_init(); L1602_string(1,1," hechao "); L1602_string(2,1,"200820103208"); //延時(shí) 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) { //查詢報(bào)警信號(hào) //FlagSet=0為報(bào)警狀態(tài), //FlagSet=1為關(guān)報(bào)警狀態(tài), //FlagSet=2,3,4,5,6,7依次為設(shè)置年,月,日,時(shí),分,秒狀態(tài) if ((FlagSet==1)&&(FlagAlert==0)&&(In_Alert==1)) //觸發(fā)報(bào)警則存入報(bào)警時(shí)間 { SaveAlert(); FlagAlert=1; Beep=0; Led_Alert = 0; } if ((FlagSet==1)&&(In_Alert==1)) { Beep=0; Led_Alert = 0; } else //報(bào)警未打開或者無警可報(bào) { FlagAlert=0; Beep=1; Led_Alert = 1; } if (FlagStartRH == 1) { //溫濕度轉(zhuǎn)換標(biāo)志檢查 TR0 = 0; testnum = RH(); FlagStartRH = 0; TR0 = 1; //讀出溫濕度,只取整數(shù)部分 humidity = U8RH_data_H; temperature = U8T_data_H; //讀出日期時(shí)間值 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); //如果不處于查詢狀態(tài)則顯示當(dāng)前日期時(shí)間溫度濕度 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); //產(chǎn)生時(shí)間設(shè)定時(shí)的閃爍效果,只在未查詢且閃爍標(biāo)志置位時(shí)運(yùn)行 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: //時(shí) L1602_string(2,1," "); break; case 6: //分 L1602_string(2,4," "); break; case 7: //秒 L1602_string(2,7," "); break; default: break; } } } } //以下為鍵盤查詢,當(dāng)有按鍵從按下到彈起時(shí),該按鍵被響應(yīng)。 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); } }
|