51 MCU Experiment Board DS18B20 Temperature Measurement Program

Publisher:开国古泉Latest update time:2012-12-05 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/***********************************************
** Experiment name: 51 single chip microcomputer experimental board temperature measurement (DS18B20)
** Creator: Xie Junyang
** Description: P3.7 port input, output data.
**------------------------------------------------------------------
** CPU: MCS-51
** Language: Assembly
** Fosc=12M The simulation diagram of this experiment ***************************************************/
Click to browse the next page

GE_BIT EQU 30H
SHI_BIT EQU 31H
BAI_BIT
EQU 32H DI_8BIT
EQU 33H GAO_8BIT EQU 34H
DQ EQU P3.7
ORG 0000H
LJMP START
ORG 0020H
START:
MOV SP,#60H
LCALL ZHUANHUAN ;Call the temperature reading subroutine
LCALL CHULI
LCALL DISPLAY ;Call the digital tube display subroutine
LJMP START

;-------------------------------------------------
;This is the DS18B20 reset initialization subroutine
INIT_1820:
SETB DQ
NOP
CLR DQ ;The host sends a reset low pulse with a delay of 537 microseconds
MOV R1,#3
DU_1:
MOV R0,#107
DJNZ R0,$
DJNZ R1,DU_1
SETB DQ ;Then pull up the data line
NOP
NOP
NOP
MOV R0,#25H
DU_2:JNB DQ,DU_3 ;Wait for DS18B20 to respond
DJNZ R0,DU_2
LJMP DU_4 ;Delay
DU_3:SETB F0 ;Set the flag bit, indicating that DS1820 exists
LJMP DU_5
DU_4:CLR F0 ;Clear the flag bit, indicating that DS1820 does not exist
LJMP DU_7
DU_5:MOV R0,#117
DU_6:DJNZ R0,DU_6 ;The timing requires a delay of some time
DU_7:SETB DQ
RET [page]
;-------------------------------------------------
;Write the subroutine of DS18B20 (with specific timing requirements)
WRITE_1820:MOV R2,#8 ;A total of 8 bits of data
CLR C
WR1:CLR DQ
MOV R3,#6
DJNZ R3,$
RRC A
MOV DQ,C
MOV R3,#23
DJNZ R3,$
SETB DQ
NOP
DJNZ R2,WR1
SETB DQ
RET

;-------------------------------------------------
;Program to read DS18B20, read two bytes of temperature data from DS18B20
READ_1820:MOV R4,#2 ;Read the high and low bits of temperature from DS18B20
MOV R1,#DI_8BIT ;Store the low bit in DI_8BIT and the high bit in GAO_8BIT
RE0:MOV R2,#8 ;There are 8 bits of data in total
RE1:CLR C
SETB DQ
NOP
NOP
CLR DQ
NOP
NOP
NOP
SETB DQ
MOV R3,#9
RE2:DJNZ R3,RE2
MOV C,DQ
MOV R3,#23
RE3:DJNZ R3,RE3
RRC A
DJNZ R2,RE1
MOV @R1,A
INC R1
DJNZ R4,RE0
/* DEC R1
MOV A,GAO_8BIT
XCHD A,@R1
XCH A,@R1
MOV GAO_8BIT,A
MOV A,@R1
SWAP A
MOV @R1,A */
RET
;-------------------------------------------------
;Read the converted temperature value
ZHUANHUAN:
//SETB DQ
LCALL INIT_1820 ;Reset DS18B20 first
JB F0,ZH1
RET ;Judge whether DS1820 exists? If DS18B20 does not exist, return to
ZH1: MOV A,#0CCH ;Skip ROM match
LCALL WRITE_1820
MOV A,#44H ;Issue temperature conversion command
LCALL WRITE_1820
LCALL DISPLAY ;Wait for AD conversion to end, 750 microseconds for 12 bits
LCALL INIT_1820 ;Reset before preparing to read temperature
MOV A,#0CCH ;Skip ROM match
LCALL WRITE_1820
MOV A,#0BEH ;Issue temperature read command
LCALL WRITE_1820
LCALL READ_1820
RET
;-------------------------------------------------
;Data processing subroutine
CHULI:
MOV P0,GAO_8BIT
MOV P2,DI_8BIT
MOV A,GAO_8BIT
JB ACC.7,FU
MOV A,DI_8BIT
MOV B,#16
DIV AB

MOV 35H,A ;Shift the high four bits of DI_8BIT right by four bits and store them in 35H (temperature value)
MOV A,B ;Multiply the low four bits of TEMPER_L by 10/16 to get the decimal point.
MOV B,#10
MUL AB
MOV B,#16
DIV AB
MOV 36H,A ;Store the decimal point in 36H
MOV A,GAO_8BIT ;Store the high eight digits in TEMPER_H, weight 16
MOV B,#16
MUL AB
ADD A,35H ;Store the integer part of the temperature value in 35H
MOV B,#10
DIV AB
MOV GE_BIT,B ;Store the ones digit in 30H
MOV B,#10 ;
DIV AB ;
MOV SHI_BIT,B ;Store the tens digit in 31H
MOV B,#10 ;
DIV AB ;
MOV BAI_BIT,B ;Store the hundreds digit in 32H
MOV A,GAO_8BIT
MOV 37H,#10H ;
JB ACC.7,EXIT
MOV 37H,#00H
SJMP EXIT
FU:
MOV A,DI_8BIT
CPL A
ADD A,#1
MOV B,#16
DIV AB
MOV 35H,A ; Shift the high 4 bits of DI_8BIT right by 4 bits and store them in 35H (temperature value)
MOV A,B ; Multiply the low 4 bits of TEMPER_L by 10/16 to get the decimal place.
MOV B,#10
MUL AB
MOV B,#16
DIV AB
// MOV 36H,A ; Store the decimal place in 36H
// MOV A,GAO_8BIT ;Store the high 8 digits in TEMPER_H, weight 16
MOV B,#16
MUL AB
ADD A,35H ;Store the integer part of the temperature value in 35H
MOV B,#10
DIV AB
MOV GE_BIT,B ;Store the ones digit in 30H
MOV B,#10 ;
DIV AB ;
MOV SHI_BIT,B ;Store the tens digit in 31H
MOV B,#10 ;
DIV AB ;
MOV BAI_BIT,B ;Store the hundreds digit in 32H
MOV A,GAO_8BIT
MOV 37H,#10H ;
JB ACC.7,EXIT
MOV 37H,#00H
SJMP EXIT
EXIT:RET [page]
;-------------------------------------------------
;Note: This ds18b20 temperature measurement experiment was conducted on the 51hei microcontroller experiment board http://www.51hei.com. The test was OK. The following is the data display subroutine
CL0:INC A
AJMP CL1
CHULI:MOV A,DI_8BIT
MOV B,#16
DIV AB
JB B.3,CL0
CL1:MOV 35H,A ;Shift the high four bits of DI_8BIT right by four bits and store them in 35H (temperature value)
MOV A,B ;Multiply the low four bits of TEMPER_L by 10/16 to get the first decimal place.
MOV B,#10
MUL AB
MOV B,#16
DIV AB
MOV 36H,A ;Store the last decimal digit in 36H
MOV A,GAO_8BIT ;Store the high 8 digits in TEMPER_H, weight 16
MOV B,#16
MUL AB
ADD A,35H ;Store the integer part of the temperature value in 35H
MOV B,#10
DIV AB
MOV GE_BIT,B ;Store the ones digit in 30H
MOV B,#10 ;
DIV AB ;
MOV SHI_BIT,B ;Store the tens digit in 31H
MOV B,#10 ;
DIV AB ;
MOV BAI_BIT,B ;Store the hundreds digit in 32H
MOV A,GAO_8BIT
MOV 37H,#10H ;
JB ACC.7,EXIT
MOV 37H,#00H
EXIT: RET */

DISPLAY:MOV DPTR,#TABLE
MOV R0,#4
XUN:MOV R1,#250 ;Display 1000 times
HUAN:MOV A,#10 //Display '-'
MOVC A,@A+DPTR
MOV P1,A
CLR P3.0
LCALL DELAY1MS
SETB P3.0

MOV A,#10 //Display '-'
MOVC A,@A+DPTR
MOV P1,A
CLR P3.1
LCALL DELAY1MS
SETB P3.1

MOV A,BAI_BIT //Display temperature in hundreds digit
MOVC A,@A+DPTR
MOV P1,A
CLR P3.2
LCALL DELAY1MS
SETB P3.2
MOV A,SHI_BIT //Display temperature in tens digit
MOVC A,@A+DPTR
MOV P1,A
CLR P3.3
LCALL DELAY1MS
SETB P3.3
MOV A,GE_BIT //Display temperature units
MOVC A,@A+DPTR
MOV P1,A
CLR P3.4
LCALL DELAY1MS
SETB P3.4

MOV A,#11 //Display \'C\'
MOVC A,@A+DPTR
MOV P1,A
CLR P3.5
LCALL DELAY1MS
SETB P3.5

MOV A,#10 //Display '-'
MOVC A,@A+DPTR
MOV P1,A
CLR P3.6
LCALL DELAY1MS
SETB P3.6

/* MOV A,#10 //Display '-'
MOVC A,@A+DPTR
MOV P1,A
CLR P3.7
LCALL DELAY1MS
SETB P3.7 */
DJNZ R1,HUAN ;250 endless loops
DJNZ R0,XUN ;4 endless loops of 250 times
RET

DELAY10MS:MOV R7,#1 //Delay 10MS subroutine
L1:NOP
DJNZ R7,L1
DELAY1MS:RET

TABLE:DB 3FH ;0
DB 06H ;1
DB 5BH ;2
DB 4FH ;3
DB 66H ;4
DB 6DH ;5
DB 7DH ;6
DB 07H ; 7 DB 7FH
;8
DB 6FH ;9
DB 01000000B ;-
DB 39H ;C
END

Reference address:51 MCU Experiment Board DS18B20 Temperature Measurement Program

Previous article:51 single chip microcomputer frequency meter program (4 digits without decimal point)
Next article:Single chip microcomputer drives 16*16 dot matrix LED Chinese character display C51 program

Recommended ReadingLatest update time:2024-11-16 15:03

MCU dynamic digital tube display DS18B20 temperature measurement display program
After days of struggling with the DS18B20 temperature display, I finally got it right. At first, it either couldn't display the temperature normally or jumped randomly. The reason is that the timing of DS18B20 reading and writing is too strict. The dynamic digital tube display in the program needs to open a timer inte
[Microcontroller]
MCU dynamic digital tube display DS18B20 temperature measurement display program
51 single chip microcomputer DS18B20 temperature measurement experiment
Experimental tasks A DS18B20 is used to form a temperature measurement system. The temperature measurement accuracy reaches 0.1 degrees. The temperature range is between -20 degrees and +50 degrees, and it is displayed with a 4-digit digital tube. DPY-1 experimental board connection Use a flat
[Microcontroller]
51 single chip microcomputer DS18B20 temperature measurement experiment
Temperature DS18b20 and PIC microcontroller communication program
 ORG PIC54      GOTO MAIN      ORG 0 ;---------------------- ;---------------------- ------ DELAY22                     MOVLW D'200' ; DELAY 2*250=500mS         MOVWF COUNT1 DE32 MOVLW D'250' ; 8*250=2mS     MOVWF COUNT2 DE42 NOP ; 1+2+1=5uS         DECFSZ COUNT2,1         GOTO DE42         DECFSZ COUNT1,1
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号