51單片機DS18B20溫度控制報警程序(可設置溫控范圍) 作者: 時間:2016-11-30 來源:網(wǎng)絡 加入技術交流群 掃碼加入和技術大咖面對面交流海量資料庫查詢 收藏 ;--------------------------------------------;200ms對閃動標記取反一次;--------------------------------------------INT_T0:PUSH ACCPUSH PSWMOV TL0,TIMER_LMOV TH0,TIMER_HINC TIMER_COUNMOV A,TIMER_COUNCJNE A,#04H,INT_ENDMOV TIMER_COUN,#00HCPL FLAG2INT_END:POP PSWPOP ACCRETI;==========================================================;重新對 DS18B20 初始化;將設定的溫度報警值寫入 DS18B20;==========================================================RE_18B20:JB FLAG1,RE_18B20ARETRE_18B20A:CALL RESETMOV A,#0CCH ;跳過ROM匹配LCALL WRITEMOV A,#4EH ;寫暫存寄存器LCALL WRITEMOV A,TEMP_TH ;TH(報警上限)LCALL WRITEMOV A,TEMP_TL ;TL(報警下限)LCALL WRITEMOV A,#7FH ;12位精確度LCALL WRITERET;====================================================;功能鍵掃描子程序;====================================================SCANKEY:;MOV P1,#0F0HJB K1,SCAN_K2CALL BEEP_BLSCAN_K1: CALL ALERT_TLCALL ALERT_PLAYJB K1,SCAN_K1CALL BEEP_BLSCAN_K11: CALL ALERT_THCALL ALERT_PLAYJB K1,SCAN_K11CALL BEEP_BLSCAN_K2: JB K2,SCAN_K3CALL BEEP_BLSCAN_K3: JB K3,SCAN_K4CALL BEEP_BLLCALL RESET_ALERTLCALL RE_18B20LCALL WRITE_E2SCAN_K4: JB K4,SCAN_ENDCALL BEEP_BLSCAN_END: RET;================================================;設置溫度報警值;================================================RESET_ALERT:CALL ALERT_TLCALL ALERT_PLAYJNB K3,$ ;K3為位移鍵SETB TR0RESET_TL:CALL ALERT_PLAYJNB FLAG2,R_TL01mov 75H,7fh ;送入熄滅符mov 76H,7fhCALL ALERT_PLAYJMP R_TL02R_TL01: CALL ALERT_TLmov 75h,7Eh ;送設定值mov 76h,7DhCALL ALERT_PLAY ;顯示設定值R_TL02: JNB K1,K011AJNB K2,K011BJNB K3,RESET_THJMP RESET_TLK011A:INC TEMP_TLMOV A,TEMP_TLCJNE A,#120,K012A ;沒有到設定上限值,轉(zhuǎn)MOV TEMP_TL,#0K012A: CALL TL_DELJMP RESET_TLK011B:DEC TEMP_TLMOV A,TEMP_TLCJNE A,#00H,K012B ;沒有到設定下限值,轉(zhuǎn)MOV TEMP_TL,#119K012B: CALL TL_DELJMP RESET_TL;-------------------------------------------------------RESET_TH:CALL BEEP_BLJNB K3,$RESET_TH1:CALL ALERT_PLAYJNB FLAG2,R_TH01mov 75H,7fh ;送入熄滅符mov 76H,7fhCALL ALERT_PLAYJMP R_TH02R_TH01: CALL ALERT_THmov 75h,7Eh ;mov 76h,7DhCALL ALERT_PLAYR_TH02: JNB K1,K021AJNB K2,K021BJNB K3,K002JMP RESET_TH1K021A:INC TEMP_THMOV A,TEMP_THCJNE A,#120,K022A ;沒有到設定上限值,轉(zhuǎn)MOV TEMP_TH,#0K022A: CALL TH_DELJMP RESET_TH1K021B:DEC TEMP_TH ;減1MOV A,TEMP_THCJNE A,#00H,K022B ;沒有到設定下限值,轉(zhuǎn)MOV TEMP_TH,#119K022B: CALL TH_DELJMP RESET_TH1K002: CALL BEEP_BLCLR TR0 ;關閉中斷RET;-----------------------------------------------------;鍵延時子程序;多次調(diào)用報警值顯示程序來延時;-----------------------------------------------------TL_DEL: ;報警低值延時MOV R2,#0AHTL_DEL1: CALL ALERT_TLCALL ALERT_PLAYDJNZ R2,TL_DEL1RETTH_DEL: ;報警高值延時MOV R2,#0AHTH_DEL1: CALL ALERT_THCALL ALERT_PLAYDJNZ R2,TH_DEL1RET;====================================================;實時溫度值與設定報警溫度值 TH、TL 比較子程序;當實際溫度大于 TH 的設定值時,顯示“H”,繼電器關閉。;當實際溫度小于 TH 的設定值時,顯示“O”,繼電器吸合。;當實際溫度小于 TL 的設定值時,顯示“L”。;閃動顯示標記符 H、L、O;====================================================TEMP_COMP:SETB TR0 ;啟動中斷MOV A,TEMP_THSUBB A,TEMP_ZH ;減數(shù)>被減數(shù),則JC CHULI1 ;借位標志位C=1,轉(zhuǎn)MOV A,TEMP_ZHSUBB A,TEMP_TL ;減數(shù)>被減數(shù),則JC CHULI2 ;借位標志位C=1,轉(zhuǎn)JNB FLAG2,T_COMP1 ;FLAG2=0,顯示標記字符MOV 74H,#0AH ;熄滅符LCALL DISP1JMP T_COMP2T_COMP1: MOV 74H,#00HLCALL DISP1 ;顯示"O"T_COMP2: CLR RELAY ;繼電器吸合CLR TR0 ;關閉中斷RET;---------------------------------------------;超溫處理;---------------------------------------------CHULI1:SETB RELAY ;繼電器關閉JNB FLAG2,CHULI10MOV 74H,#0AH ;熄滅符LCALL DISP1JMP CHULI11CHULI10: MOV 74H,#0DH LCALL DISP1 ;顯示"H";CALL BEEP_BL ;蜂鳴器響CHULI11:CLR TR0 ;關閉中斷RET;---------------------------------------------;欠溫處理;---------------------------------------------CHULI2: ;欠溫處理JNB FLAG2,CHULI20MOV 74H,#0AH ;熄滅符LCALL DISP1JMP CHULI21CHULI20: MOV 74H,#0CH LCALL DISP1 ;顯示"L";CALL BEEP_BL ;蜂鳴器響CHULI21: CLR TR0 ;關閉中斷RET;------------------------------------------------------------;把 DS18B20 暫存器里的溫度報警值拷貝到EEROM;------------------------------------------------------------WRITE_E2:CALL RESETMOV A,#0CCH ;跳過ROM匹配LCALL WRITEMOV A,#48H ;溫度報警值拷貝到EEROMLCALL WRITERET;--------------------------------------------------------------;把 DS18B20 EEROM 里的溫度報警值拷貝回暫存器;-------------------------------------------------------------READ_E2:CALL RESETMOV A,#0CCH ;跳過ROM匹配LCALL WRITEMOV A,#0B8H ;溫度報警值拷貝回暫存器CALL WRITERET 上一頁 1 2 3 下一頁
評論