51單片機(jī)DS18B20溫度控制報(bào)警程序(可設(shè)置溫控范圍) 作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 加入技術(shù)交流群 掃碼加入和技術(shù)大咖面對(duì)面交流海量資料庫(kù)查詢(xún) 收藏 ;*****************************************************; 處理溫度 BCD 碼子程序;****************************************************CONVTEMP: MOV A,TEMPH ;判溫度是否零下ANL A,#80HJZ TEMPC1 ;溫度零上轉(zhuǎn)CLR CMOV A,TEMPL ;二進(jìn)制數(shù)求補(bǔ)(雙字節(jié))CPL A ;取反加1ADD A,#01HMOV TEMPL,AMOV A,TEMPH ;-CPL AADDC A,#00HMOV TEMPH,A ;TEMPHC HI =符號(hào)位MOV TEMPHC,#0BHSJMP TEMPC11TEMPC1: MOV TEMPHC,#0AH ;TEMPC11: MOV A,TEMPHCSWAP AMOV TEMPHC,AMOV A,TEMPLANL A,#0FH ;乘0.0625MOV DPTR,#TEMPDOTTABMOVC A,@A+DPTRMOV TEMPLC,A ;TEMPLC LOW=小數(shù)部分 BCDMOV A,TEMPL ;整數(shù)部分ANL A,#0F0HSWAP AMOV TEMPL,AMOV A,TEMPHANL A,#0FHSWAP AORL A,TEMPLMOV TEMP_ZH,A ;組合后的值存入TEMP_ZHLCALL HEX2BCD1MOV TEMPL,AANL A,#0F0HSWAP AORL A,TEMPHC ;TEMPHC LOW = 十位數(shù) BCDMOV TEMPHC,AMOV A,TEMPLANL A,#0FHSWAP A ;TEMPLC HI = 個(gè)位數(shù) BCDORL A,TEMPLCMOV TEMPLC,AMOV A,R7JZ TEMPC12ANL A,#0FHSWAP AMOV R7,AMOV A,TEMPHC ;TEMPHC HI = 百位數(shù) BCDANL A,#0FHORL A,R7MOV TEMPHC,ATEMPC12: RET;-----------------------------------------------------------; 小數(shù)部分碼表;-----------------------------------------------------------TEMPDOTTAB: DB 00H,01H,01H,02H,03H,03H,04H,04H,05H,06HDB 06H,07H,08H,08H,09H,09H;===========================================================;顯示區(qū) BCD 碼溫度值刷新子程序;===========================================================DISPBCD: MOV A,TEMPLCANL A,#0FHMOV 70H,A ;小數(shù)位MOV A,TEMPLCSWAP AANL A,#0FHMOV 71H,A ;個(gè)位MOV A,TEMPHCANL A,#0FHMOV 72H,A ;十位MOV A,TEMPHCSWAP AANL A,#0FHMOV 73H,A ;百位MOV A,TEMPHCANL A,#0F0HCJNE A,#010H,DISPBCD0SJMP DISPBCD2DISPBCD0: MOV A,TEMPHCANL A,#0FHJNZ DISPBCD2 ;十位數(shù)是0MOV A,TEMPHCSWAP AANL A,#0FHMOV 73H,#0AH ;符號(hào)位不顯示MOV 72H,A ;十位數(shù)顯示符號(hào)DISPBCD2: RET;***************************************************************; 溫度顯示子程序;***************************************************************;顯示數(shù)據(jù)在70H - 73H 單元內(nèi),用4位共陽(yáng)數(shù)碼管顯示,P0口輸出段碼數(shù)據(jù),;P0 口作掃描控制,每個(gè) LED 數(shù)碼管亮 2MS 時(shí)間再逐位循環(huán)。DISP1: MOV R1,#70H ;指向顯示數(shù)據(jù)首址MOV R5,#7FH ;掃描控制字初值PLAY: ; MOV P0,#0FFHMOV A,R5 ;掃描字放入AMOV P0,ASETB P2.7CLR P2.7MOV A,@R1 ;取顯示數(shù)據(jù)到AMOV DPTR,#TAB ;取段碼表地址MOVC A,@A+DPTR ;查顯示數(shù)據(jù)對(duì)應(yīng)段碼MOV P0,A ;段碼放入P0口SETB P2.6CLR P2.6MOV A,R5JB ACC.6,LOOP5 ;小數(shù)點(diǎn)處理SETB P0.7SETB P2.6CLR P2.6LOOP5: LCALL DL_MS ;顯示2MSINC R1 ;指向下一個(gè)地址MOV A,R5 ;放回 R5 內(nèi)JNB ACC.3,ENDOUT ;ACC.3=0時(shí)一次顯示結(jié)束RR A ;A 中數(shù)據(jù)循環(huán)左移MOV R5,A ;放入 R5 中AJMP PLAY ;跳回 PLAY 循環(huán)ENDOUT: ; MOV P0,#0FFH ;一次顯示結(jié)束,P0口復(fù)位; MOV P2,#0FFH ;P2口復(fù)位RETTAB:;定義段碼對(duì)應(yīng) 0 1 2 3 4 5 6 7 8 9 - L H DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,00H,40H,38H,76HDL_MS: MOV R6,#0AH ;2MS延時(shí)程序,LED 顯示程序用DL1: MOV R7,#64HDL2: DJNZ R7,DL2DJNZ R6,DL1MOV P0,#00H ;消隱SETB P2.6CLR P2.6RET;******************************************************;單字節(jié)十六進(jìn)制轉(zhuǎn) BCD;******************************************************HEX2BCD1: MOV B,#064H DIV AB MOV R7,A MOV A,#0AHXCH A,BDIV AB SWAP AORL A,BRET;===============================================;報(bào)警值 TH、TL 數(shù)據(jù)轉(zhuǎn)換;===============================================ALERT_TL:MOV 79H,#0CHMOV 78H,#0BHMOV A,TEMP_TLMOV R0,#77HMOV B,#064HDIV ABCJNE A,#01H,ALERT_TL1MOV @R0,AJMP ALERT_TL2ALERT_TL1: MOV A,#0BH ;顯示“-”MOV @R0,AALERT_TL2: MOV A,#0AHXCH A,BDIV ABDEC R0MOV @R0,AMOV 7DH,ADEC R0MOV @R0,BMOV 7EH,BRET;-----------------------------------------------ALERT_TH:MOV 79H,#0DHMOV 78H,#0BHMOV A,TEMP_THMOV R0,#77HMOV B,#064HDIV ABCJNE A,#01H,ALERT_TH1MOV @R0,AJMP ALERT_TH2ALERT_TH1: MOV A,#0BH ;顯示“-”MOV @R0,AALERT_TH2: MOV A,#0AHXCH A,BDIV ABDEC R0MOV @R0,AMOV 7DH,ADEC R0MOV @R0,BMOV 7EH,BRET;===============================================;報(bào)警值顯示子程序;===============================================ALERT_PLAY:MOV R1,#75H ;指向顯示數(shù)據(jù)首址MOV R5,#7FH ;掃描控制字初值A(chǔ)_PLAY: ; MOV P0,#0FFHMOV A,R5 ;掃描字放入AMOV P0,ASETB P2.7CLR P2.7MOV A,@R1 ;取顯示數(shù)據(jù)到AMOV DPTR,#ALERT_TAB ;取段碼表地址MOVC A,@A+DPTR ;查顯示數(shù)據(jù)對(duì)應(yīng)段碼MOV P0,A ;段碼放入P0口SETB P2.6CLR P2.6LCALL DL_MS1 ;顯示2MSINC R1 ;指向下一個(gè)地址MOV A,R5JNB ACC.3,ENDOUT1RR A ;A 中數(shù)據(jù)循環(huán)左移MOV R5,A ;放入 R5 中AJMP A_PLAY ;跳回 PLAY 循環(huán)ENDOUT1: ; MOV P0,#0FFH ;一次顯示結(jié)束,P0口復(fù)位; MOV P2,#0FFH ;P2口復(fù)位RETALERT_TAB:;定義段碼對(duì)應(yīng) 0 1 2 3 4 5 6 7 8 9 - L H DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,00H,40H,38H,76HDL_MS1: MOV R6,#0AH ;2MS延時(shí)程序,LED 顯示程序用ADL1: MOV R7,#64HADL2: DJNZ R7,ADL2DJNZ R6,ADL1MOV P0,#00H ;消隱SETB P2.6CLR P2.6RET;===============================================;蜂鳴器響一聲子程序;P3.7=0,蜂鳴器響;===============================================BEEP_BL:MOV R6,#100BL2: CALL DEX1CPL BEEP ;對(duì) beep 取反DJNZ R6,BL2MOV R5,#10CALL DELAYRETDEX1: MOV R7,#180DE2: NOPDJNZ R7,DE2RETDELAY: ;(R5)*延時(shí)10MSMOV R6,#50DEL1: MOV R7,#100DJNZ R7,$DJNZ R6,DEL1DJNZ R5,DELAYRET;==================================================END 上一頁(yè) 1 2 3 下一頁(yè)
評(píng)論