单片机温度检测系统的汇编实现(Compilation of temperature detection system for single chip microcomputer)_第1页
单片机温度检测系统的汇编实现(Compilation of temperature detection system for single chip microcomputer)_第2页
单片机温度检测系统的汇编实现(Compilation of temperature detection system for single chip microcomputer)_第3页
单片机温度检测系统的汇编实现(Compilation of temperature detection system for single chip microcomputer)_第4页
单片机温度检测系统的汇编实现(Compilation of temperature detection system for single chip microcomputer)_第5页
已阅读5页,还剩44页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、单片机温度检测系统的汇编实现(Compilation of temperature detection system for single chip microcomputer)Digital thermometer assembly language source code is as follows:* temperature value * storage unit;TEMP_ZH EQU 24H; real time temperature value storage unitTEMPL EQU 25H; low temperature value storage unitTEMPH

2、EQU 26H; high temperature value storage unitTEMP_TH EQU 27H; high temperature alarm value storage unitTEMP_TL EQU 28H; low temperature alarm value storage unitTEMPHC EQU 29H; keep ten digit BCD codesTEMPLC, EQU, 2AH; BCD codes for individual bits*; key input pin definition *K1 EQU P1.0K2 EQU P1.1K3

3、EQU P1.2K4 EQU P1.3SPK EQU P3.7; buzzerZF EQU 22H.1X EQU 2FH; sets the display position*LCD control * pin;RS EQU P2.0RW EQU P2.1E EQU P2.2FLAG EQU 21H.0; temperature sensor flag bitKEY_UD EQU 21H.1DQ EQU P3.3; temperature sensor data acquisition portThe main program * *;ORG 0000HLJMP MAINORG 0023HOR

4、G 0030HMAIN:, MOV, SP, #5FHMOV TMOD, #20H; the timer T1 is the 2 (auto reload 8 bit counter)MOV, TH1, #0F3H; set the timer initial value,MOV, TL1, #0F3HSETB TR1; timer startMOV, TEMP_TH, #27MOV, TEMP_TL, #20ACALL SET_LCD; LCD initialization setting subroutineTOOP: ACALL RESET_1820; call the 18B20 re

5、set subroutineJNB, FLAG, TOOP1; DS1820 does not exist, then jumpACALL XS_S; call the SUCCES information subroutineACALL WR_THL; writes the alarm upper and lower limits to the scratchpad register subroutineACALL RE_THL; copies the temperature alarm values in the E2ROM back to the registersJMP TOOP2TO

6、OP1: ACALL XS_WRONG; displays WRONG informationSJMP TOOP; returns, continues to judgeTOOP2: ACALL RE_TEMP; call read temperature data subroutineACALL SET_DATA; call processing to display temperature data subprogramACALL TEMP_COMP; the actual temperature value is compared with the marked temperature

7、value subroutineACALL P_KEY; call key scan subroutineJMP TOOP2; loop*; read the temperature data * subroutineRE_TEMP:JNB, FLAG, TOOP1; determine whether DS18B20 existsACALL RESET_1820; 18B20 reset subroutineMOV, A, #0CCH; skip the ROM matchACALL WRITE_1820MOV, A, #44H; issue a temperature conversion

8、 commandACALL WRITE_1820ACALL RESET_1820; call reset subroutineMOV, A, #0CCH; skip the ROM matchACALL WRITE_1820MOV, A, #0BEH; issue a read temperature commandACALL WRITE_1820ACALL READ_1820; call read subroutineRET*; temperature display data processing subroutine *SET_DATA:ACALL CONV_TEMP; processi

9、ng temperature; BCD code subroutineACALL DISP_BCD;Display area, BCD code, temperature value, refresh subroutineACALL CONV; LCD display subroutineMOV, A, #0CBH; sets the second line start addressACALL TEMP_BJ; display temperature mark centigradeACALL zhfuRET* keyboard scanning subroutine *;P_KEY:; bu

10、tton K1 processingJB K1, PK1; K1 key is not pressed, then jump to PK1ACALL SPK_BZ; the K1 button is pressed to make a noiseJNB, K1, $, etc. release the keyMOV, DPTR, #M_ALAX1; save the M_ALAX1 tableMOV, A, #1ACALL LCD_PRINT; display charactersACALL LOOK_ALARM; display information area subroutineJB K

11、3, $; wait for K3 to press (return)ACALL SPK_BZ; make a noiseJMP PK2; go to label PK2PK1:; button K2 processingJB K2, PK3; K2 key is not pressed, then jump to PK3ACALL SPK_BZ; the K2 button is pressed to make a noiseJNB, K2, $, etc. key releaseMOV, DPTR, #TA1; save the #TA1 tableMOV, A, #01ACALL LCD

12、_PRINT; display charactersACALL LOOK_ALARM; call the display information area subroutineACALL SET_ALARM; set alarm values TH, TLACALL WR_THL; writes the set TH and TL values to the DS18B20ACALL WRITE_E2; call the alarm value to copy the E2ROM subroutinePK2: ACALL XS_S; displays the OK message subrou

13、tinePK3: RETTA1:; menu tableDB SET ALERT DATA, 0H*; set the alarm value of TH, TL * subroutineSET_ALARM:A0:, JB, K1, A2; press the K1 program to run downACALL SPK_BZ; the buzzer ringsJNB, K1, $; wait for releaseCPL KEY_UD; UP/DOWN tag reverseA2:, JB, KEY_UD, A3, 20H.1=1, UP, jump to A3JMP A8; 20H.1=

14、0, DOWN, jump to A8TH value adjustment (increase)A3:, JB, K2, A5; press the K2 key, and the program runs downACALL SPK_BZ; the buzzer ringsINC TEMP_TH; TH value adjustment (increase)MOV, A, TEMP_TH; TH values are fed into ACJNE, A, #120, A4; TH value increased to 120, the program runs downMOV, TEMP_

15、TH, #0; TH value 0A4: ACALL LOOK_ALARM; call the display information area subroutineMOV, R5, #10ACALL DELAY; call delay programJMP A3; loopTL value adjustment (increase)A5:, JB, K3, A7; press the K3 key to run downACALL SPK_BZ; the buzzer ringsINC TEMP_TL; TL value increased by 1MOV, A, TEMP_TL; TL

16、values are fed into ACJNE, A, #119, A6; compare, if A=99, the program runs downMOV, TEMP_TL, #00H; TL value 0A6: ACALL LOOK_ALARM; call the display information area subroutineMOV, R5, #10ACALL DELAY; call delay programJMP A5; program jump to A5, loopTo determine the adjustment of OKA7:, JB, K4, A0;

17、press the K4 key, and the program runs downACALL SPK_BZ; the buzzer ringsJNB, K4, $, etc., let goRETTH value adjustment (decrease)A8:, JB, K2, A10; press the K2 key, and the program runs downACALL SPK_BZ; the buzzer ringsDEC TEMP_TH; TH minus 1MOV, A, TEMP_TH; TH values are fed into ACJNE, A, #0FFH,

18、 A9; compare, if A=0FF, the program runs downJMP A12; jump to A12A9: ACALL LOOK_ALARM; call the display information area subroutineMOV, R5, #10ACALL DELAY; call delay subroutineJMP A0; jump to A0TL value adjustment (decrease)A10:JB, K3, A13; press the K3 key, and the program runs downACALL SPK_BZ; t

19、he buzzer ringsDEC TEMP_TL; TL minus 1MOV, A, TEMP_TL; TH values are fed into ACJNE, A, #0FFH, A11; compare, if A=0FFH, the program runs downJMP A12; transferred to A12A11:ACALL LOOK_ALARM; call the display information area subroutineMOV, R5, #10ACALL DELAY; call delay subroutineJMP A0; transferred

20、to A0A12:CPL 20H.1; UP/DOWN tag reverseJMP A3; jump to A3, TH value adjustment (increase)A13:JMP A7; jump to A7 and make sure to adjust OKRET; subroutine returns* menu display subroutine statement;Display characters on the first or second line of the LCDLCD_PRINT:CJNE, A, #1, LINE2; determine whethe

21、r it is the first lineLINE1:ACALL CLR_LINE; clears the row character dataMOV A, #80H; sets the first line address of the LCDACALL WR_COMM; write commandJMP FILLLINE2:ACALL CLR_LINE; clears the row character dataMOV, A, #0C0H; sets the second line address of LCDACALL WR_COMM; write commandFILL:CLR AM

22、OVC, A, A+DPTR; the characters are extracted from the message areaCJNE, A, #0, LC1; determine whether it is the end codeRETLC1:ACALL WR_DATA; write dataINC DPTR; pointer plus 1JMP FILL; continue filling in characters* display subroutine * information area;LOOK_ALARM:MOV, DPTR, #M_ALAX2; storage tabl

23、eMOV, A, #2; shown in the second lineACALL LCD_PRINT; call the display character subroutineMOV, A, #0C6H; display start address second lines seventh bitACALL TEMP_BJ; call the display temperature flag subroutineMOV, A, TEMP_TH; load TH dataMOV, X, #3; set the locationACALL SHOW_LINE2H; display data;

24、MOV, A, #0CEH; sets the display start address to second rows and fifteenth bitsACALL TEMP_BJ; call the display temperature flag subroutineMOV, A, TEMP_TL; load TL dataMOV, X, #12; set the locationACALL SHOW_LINE2L; display dataRETM_ALAX1:DB LOOK TH, &, TL DATA, 0HM_ALAX2:DB TH: TL:, 0HHigh temperatu

25、re digital display; applied * in LCD secondSHOW_LINE2H:MOV, B, #100; sets the dividend, and B is the hundredsDIV AB; division operation; result A quotient; B remainderADD, A, #30H; low half byte plus 30, get ASCII codePUSH B; B is put into the stack for temporary storageMOV, B, X; sets the location

26、of the LCD displayACALL LCDP2; displayed by LCD;POP B; B is taken out of the stackMOV, A, #0AH; A assignment 10XCH, A, B, A, B, data interchange, B for ten digitsDIV AB; division operation; result A into quotient,B save remainderADD, A, #30H; converted to charactersINC X; LCD display bit position pl

27、us 1PUSH B; B is put into the stack for temporary storageMOV, B, X; sets the location of the LCD displayACALL LCDP2; displayed by LCD;POP B; B is taken out of the stackINC X; LCD display bit position plus 1MOV, A, B; B is a single digit numberMOV, B, X; sets the location of the LCD displayADD, A, #3

28、0H; converted to charactersACALL LCDP2; displayed by LCDRET*-; low temperature display in LCD second digital *SHOW_LINE2L:MOV, B, #100; set dividendDIV AB; division operation; result A quotient; B remainderMOV, A, #0AH; A assignment 10XCH, A, B, A, B data interchange, B for ten digitsDIV AB; divisio

29、n operation; result A quotient; B remainderADD, A, #30H; converted to charactersPUSH B; the B press in stack is temporarily storedMOV, B, X; sets the location of the LCD displayACALL LCDP2; displayed by LCD;POP B; B is taken out of the stackINC X; LCD display bit position plus 1MOV, A, B; B is a sin

30、gle digit numberMOV, B, X; sets the location of the LCD displayADD, A, #30H; converted to charactersACALL LCDP2; displayed by LCDRETComparison of * * temperature subroutine;The actual temperature is compared with the marked temperatureTEMP_COMP:MOV, A, TEMP_TH; high temperature alarm value is sent t

31、o ASUBB A, TEMP_ZH; meiosis minuend is.JC TCL1; C=1 TCL1 to borrow the flag.MOV, A, TEMP_ZH; real time temperature is fed into ASUBB A, TEMP_TL; meiosis minuend is.JC TCL2; C=1 TCL2 to borrow the flag.MOV, DPTR, #BJ5; store table BJ5ACALL TEMP_BJ3; call display high, low temperature and heating mark

32、 subroutineRET*; real time temperature value temperature alarm handler *TCL1:MOV, DPTR, #BJ3; deposit the #BJ3 tableACALL TEMP_BJ3; call display high, low temperature and heating mark subroutineACALL SPK_BZ; call ringing subroutineRETTCL2:; real-time temperature high temperature alarm value processi

33、ng programMOV, DPTR, #BJ4; deposit the #BJ4 tableACALL TEMP_BJ3; call display high, low temperature and mark subroutineACALL SPK_BZ; call ringing subroutineRET* display; high and low temperature and heating program * markTEMP_BJ3:MOV, A, #0CEH; sets the display positionACALL WR_COMM; call write inst

34、ruction subroutineMOV, R1, #0; make the pointer refer to the first code in the tableMOV, R0, #2; fetch timesBJJ:MOV, A, R1; A bit 0MOVC, A, A+DPTR; read codeACALL WR_DATA; call write data subroutineINC R1; R1 increased by 1DJNZ, R0, BJJ; make sure that the code is readRETBJ3:DB HBJ4:DB LBJ5:DB!*; al

35、arm line write register * subroutineWR_THL:JB, FLAG, WR_T; FLAG=1, indicating the presence of DS18B20, transferred to WR_TRETWR_T:ACALL RESET_1820;Call the 18B20 reset subroutineMOV, A, #0CCH; skip the ROM matchACALL WRITE_1820MOV, A, #4EH; write temporary registersACALL WRITE_1820MOV, A, TEMP_TH; T

36、H (alarm upper limit)ACALL WRITE_1820MOV, A, TEMP_TL; TL (alarm lower limit)ACALL WRITE_1820MOV, A, #7FH; 12 bit accuracyACALL WRITE_1820RET*; alarm value is copied to the EEROM subroutine *WRITE_E2:ACALL RESET_1820; call the 18B20 reset subroutineMOV, A, #0CCH; skip the ROM matchLCALL WRITE_1820MOV

37、, A, #48H; 48H as copy to EEROM subroutineLCALL WRITE_1820RET*; alarm value register copy back * subroutineRE_THL:ACALL RESET_1820; call the 18B20 reset subroutineMOV, A, #0CCH; skip the ROM matchLCALL WRITE_1820MOV, A, #0B8H; copy the temperature alarm values in the EEROM back to the registersACALL

38、 WRITE_1820RET* temperature; BCD code * subroutineCONV_TEMP:MOV, A, TEMPH; judge if the temperature is below zeroANL, A, #80HJZ TC1; A is zero, the temperature is positive, and goes to TC1Negative value;CLR C; C=0Setb ZF; when 1, the temperature is negativeMOV, A, TEMPL; binary number complementCPL

39、A; take reverse plus 1ADD, A, #01HMOV, TEMPL, AMOV, A, TEMPHCPL AADDC, A, #00HMOV, TEMPH, AJMP TC2TC1:clr ZF; for 0, the temperature is positiveMOV, TEMPHC, #0AHTC2:MOV, A, TEMPHCSWAP A; high and low switchingMOV, TEMPHC, AMOV, A, TEMPLANL, A, #0FH; multiply 0.0625MOV, DPTR, #DOTTABMOVC, A, A+DPTRMO

40、V, TEMPLC, A; TEMPLC; low is the decimal part, BCD;MOV, A, TEMPL; integer partANL, A, #0F0H; take out 4 bitsSWAP AMOV, TEMPL, AMOV, A, TEMPHANL, A, #0FH; take out 4 bit lowSWAP A; high and low switchingORL, A, TEMPL; regroupMOV, TEMP_ZH, ALCALL HEX2BCD1MOV, TEMPL, AANL, A, #0F0H; take out 4 bitsSWAP

41、 A; high and low switchingORL, A, TEMPHC; TEMPHC, low for ten bit values, BCDMOV, TEMPHC, AMOV, A, TEMPLANL, A, #0FH; take out 4 bit lowSWAP A; high and low switchingORL, A, TEMPLC, TEMPLC, high bit value, BCDMOV, TEMPLC, AMOV, A, R4JZ TC3; hundred bits do not go down for 0ANL, A, #0FH; take out 4 b

42、it lowSWAP AMOV, R4, A;MOV, A, TEMPHC; TEMPHC high for 100 bit values, BCDANL, A, #0FH; take out the ten bit value of TEMPORL, A, R4MOV, TEMPHC, A; store ten and 100 bit valuesTC3:RETBCD code; * display area temperature subroutine which refreshDISP_BCD:MOV, A, TEMPLC; single digit BCD code is sent i

43、nto AANL, A, #0FH; take the low bit codeMOV, 70H, A; decimal valuesMOV, A, TEMPLCSWAP A; high and low switchingANL, A, #0FH; take the high number of resultsMOV 71H,A; bit valueMOV, A, TEMPHCANL, A, #0FH; take the low bit codeMOV, 72H, A; ten bit valuesMOV, A, TEMPHCSWAP A; high and low switchingANL,

44、 A, #0FH;MOV, 73H, A, hundred bit valuesMOV, A, TEMPHCANL, A, #0F0HCJNE, A, #010H, DI0; determine whether a hundred is 0, or jumpMOV, 73H, A; if one hundred is 1DI0:MOV, A, TEMPHC; one hundred for 0, and the next.ANL, A, #0FH; take ten bit valuesMOV, A, TEMPLCSWAP AANL, A, #0FH; take the high number

45、 of resultsMOV, 73H, #20h; symbol bits are not displayedMOV, 72H, #0; ten digit display symbolsRETHEX2BCD1:MOV, B, #100; sixteen decimal to BCDDIV ABMOV, R4, A; R4 for hundreds of digitsMOV, A, #0AHXCH, A, BDIV ABSWAP A; high and low switchingORL, A, BRETThe decimal part of table;DOTTAB:DB, 00H, 00H

46、, 01H, 01H, 02H, 03H, 03H, 04HDB, 05H, 05H, 06H, 06H, 07H, 08H, 08H, 09H*DS18B20 initialization subroutine * reset;RESET_1820:SETB DQNOPCLR DQThe host sends a reset pulse of time delay 537usMOV, R1, #3DLY:MOV, R0, #107DJNZ R0, $DJNZ, R1, DLYThe;SETB DQ; then pull up the data lineNOPNOPNOPWait for DS

47、18B20 responseMOV, R0, #25HT2:, JNB, DQ, T3, 0 time hopDJNZ, R0, T2JMP T4Setting the flag bit FLAG=1 indicating the presence of DS18B20T3: SETB FLAGJMP T5The clear flag bit FLAG=0 indicates that the DS18B20 does not existT4: CLR FLAGJMP T7Time required for a period of timeT5:, MOV, R0, #117T6:, DJNZ

48、, R0, T6T7: SETB DQRETWrite DS18B20 subroutine * *;Write to DS18B20WRITE_1820:MOV, R2, #8; a total of 8 bits of dataCLR C; C=0WR1:CLR DQ; the bus is low and starts writingMOV, R3, #6DJNZ R3, $; keep above 16usRRC A; divides the byte DATA into 8 bits and moves the ring to the CMOV, DQ, C; writes a bitMOV, R3, #23DJNZ, R3, $; waitSETB DQ; re - release the busNOPDJNZ, R2, WR1; write to the next bitSETB DQ; release busRET-*; DS18B20 read subroutine *Temperature values are read from the DS18B20READ_1820:MOV, R4, #4MOV, R1, #TEMPL; deposit 25H, 26H, 27H, 28HRE0:

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论