DS18B20 reads temperature and displays it - assembly program

Publisher:JoyousJourneyLatest update time:2012-10-31 Source: 21ic Keywords:DS18B20 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

*
Program effect: Read the temperature value through DS18B20 and display the corresponding temperature value
The program focuses on understanding the timing and delay time
*/

DS18DQ EQU P1.3 //P1.3 is equivalent to DS18DQ, which is easy to understand
SPEAKER EQU P2.0 //Drive the buzzer
TEMPH EQU 29H //Save the low 8 bits of the temperature read
TEMPL EQU 28H //Save the high 8 bits of the temperature read
DS18FLAG EQU 40H //Set the flag
ORG 0000H
LJMP START
ORG 0030H
START: MOV 30H,#00 //Set the initial value
MOV 31H,#00
MOV 32H,#00
START1: LCALL DS18_GF //Set the working mode of DS18B20
LCALL CONVERT_TEMPERATURE //Output conversion temperature command
LCALL DELAY750MS //Delay 750ms
LCALL GET_TEMPERATURE //Get temperature data
LCALL CAL_TEMPERATURE //Calculate temperature value
LCALL DISPLAY //Call the display to prevent the display from dropping
LJMP START1 //Infinite loop
//Initialize the subroutine
DS18_START:
PUSH 07H //Save the value of R7 to prevent changing the value of R7
SETB DS18DQ //Pull the data line high
NOP //Delay 1us
CLR DS18DQ //Pull the data line low
MOV R7,#0 //Delay about 512us
DJNZ R7,$
SETB DS18DQ //Pull the data line high
MOV R7,#40
DS18_START1: //Delay about 160us
JNB DS18DQ,DS18_START2 //Check if DS18B20 is working properly
DJNZ R7,DS18_START1
SETB DS18FLAG //Abnormal work
CLR SPEAKER //Drive the buzzer and alarm
DS18_START2:
CLR DS18FLAG
MOV R7,#100 //Delay month 200us
DJNZ R7,$
POP 07H //Restore the value of R7
RET
//Set DS18B20 working mode
DS18_GF:CLR DS18FLAG //Clear flag
LCALL DS18_START //Call initialization subroutine
MOV A,#0CCH //Jump ROM instruction
LCALL DS18_SEND //
MOV A,#4EH //Write data to RAM
LCALL DS18_SEND
MOV A,#75
LCALL DS18_SEND
MOV A,#0
LCALL DS18_SEND
MOV A,#7FH //Set working mode
LCALL DS18_SEND
CLR DS18DQ //Release bus
LCALL DELAY500US //Delay 500us
LOOP: LCALL CONVERT_TEMPERATURE //Call rotor program
MOV R5,#80
LOOP1: LCALL DISPLAY //Call display to prevent display dropout and wait for conversion to complete
DJNZ R5,LOOP1
LCALL GET_TEMPERATURE //Get conversion value
LCALL CAL_TEMPERATURE //Calculate temperature value
LJMP LOOP
RET[page]
//Output conversion temperature command
CONVERT_TEMPERATURE:
LCALL DS18_START //Call initialization subroutine
MOV A,#0CCH //Jump ROM instruction
LCALL DS18_SEND
MOV A,#44H //Temperature conversion
LCALL DS18_SEND
RET
//Read temperature data
GET_TEMPERATURE:
LCALL DS18_START //Call initialization subroutine
MOV A,#0CCH //Jump ROM instruction
LCALL DS18_SEND
MOV A,#0BEH //Data from RAM
LCALL DS18_SEND
LCALL DELAY60US
LCALL DS18_READ
MOV TEMPL,A //Store the lower eight bits of the obtained data in TEMPL
LCALL DS18_READ
MOV TEMPH,A //Store the upper eight bits of the obtained data in TEMPH
CLR DS18DQ //Reset. Otherwise, it will keep reading until
LCALL DELAY501US //Store the ninth byte temporarily
RET
//Calculate the temperature value for easy display
CAL_TEMPERATURE:
PUSH 07H //Store temporarily to prevent changing the data in R7
CLR C //Clear the carry flag
MOV R7,#04H //Number of cycles

EX2: MOV A,TEMPH // The functions of these statements are:
RRC A // The integer bit is in: TEMPL
MOV TEMPH,A // The integer bit is in: the high half of TEMPH
MOV A,TEMPL
RRC A
MOV TEMPL,A
DJNZ R7,EX2 //

MOV A,TEMPH //
RLC A //The functions of these statements are:
RLC A //Move the high half of TEMPH to the low four bits
RLC A
RLC A //
ANL A,#0FH //Shield the high four bits and keep the low four bits
MOV DPTR,#TAB_TEMP //Assign the first address of the value table with a decimal point
MOVC A,@A+DPTR
MOV 30H,A //Store the value temporarily for display
MOV A,TEMPL
CLR C
MOV B,#0AH
DIV AB //Separate the high and low four bits of the integer
MOV 32H,A //Store the tens digit temporarily
MOV A,B
ADD A,#10H
MOV 31H,A //Store the ones digit temporarily
POP 07H //Restore the value of R7
RET
//Write data subroutine
DS18_SEND:
PUSH 06H //Protect the value of Rn
PUSH 07H
//The following statements are "write pen and mouse"
SETB DS18DQ //The write timing is determined by the falling edge of DS18DQ
NOP //Delay 1us
MOV R6,#08H //Number of loops, one byte
DS18_SEND1:
CLR DS18DQ //Pull low to generate a falling edge
MOV R7,#07 //Delay about 15us
DJNZ R7,$
RRC A //Move the high bit of the data to be written to C
MOV DS18DQ,C //Then assign the value of C to DS18DQ
MOV R7,#30 //Delay time is about 60us, only about 45us is needed
DJNZ R7,$
SETB DS18DQ //Pull high to prepare, the next falling edge will be generated
DJNZ R6,DS18_SEND1 //Judge whether the number of loops is enough
POP 07H //Restore the data of Rn
POP 06H
RET
The full program is too long, please download it from here: http://www.51hei.com/ziliao/file/ds182051hei.asm

This program has been tested successfully.

Keywords:DS18B20 Reference address:DS18B20 reads temperature and displays it - assembly program

Previous article:C51 program for adjustable time alarm clock
Next article:PWM control LED desk lamp program with infrared remote control

Recommended ReadingLatest update time:2024-11-16 19:59

C language program using DS18B20 temperature sensor in single chip microcomputer (reference 6)
/******************************************/ // // DS18B20 thermometer C program // 2007.06.08 /******************************************/ //Use AT89C2051 microcontroller, 12MHZ crystal oscillator, common anode LED digital tube //P1 port outputs segment code, P3 port scans, P3.4 connects to DS18B20 #include "r
[Microcontroller]
51 single-chip multi-channel DS18B20 temperature measurement display and serial number reading
/**************************************************** Function: Read serial number and match serial number, and read temperature value Multifunctional test board showing multi-channel temperature acquisition Normally display the temperature of 2 DS18B20 Read the DS18B20 serial number normally Microcontroller: STC1
[Microcontroller]
51 single-chip multi-channel DS18B20 temperature measurement display and serial number reading
DS18B20 assembly program and C program
ds18b20 c program //DS1820 C51 subroutine //Here we take 11.0592M crystal as an example. Different crystal speeds may require adjustment of the delay time //sbit DQ = P2^1; //Define the port according to actual conditions  typedef unsigned char byte; typedef unsigned int word; //delay void delay(word useconds) { for
[Microcontroller]
51 MCU-Temperature Control-PID Algorithm-DS18B20-C Language
#include #include intrins.h #include math.h #include string.h struct PID { unsigned int SetPoint; // Set the desired value unsigned int Proportion; // Proportional Const unsigned int Integral; // Integral Const unsigned int Derivative; // differential constant Derivative Const unsigned int LastError;
[Microcontroller]
DS18B20 temperature measurement and display program
#include #include intrins.h sbit TSOR=P2^0; #define Busy 0x80; #define uchar unsigned char #define uint unsigned int #define reset() {WDT=0x1e;WDT=0xe1;} sfr WDT=0xa6; bit ON_OFF; bit outflag; sbit en =P1^7; /*DTLED-6 display chip enable terminal*/  sbit dout=P1^6; /*DTLED-6 display chip data reading termi
[Microcontroller]
LG Display plans to extend LCD panel production in South Korea for another year
Samsung Electronics is expected to invest more than $30 billion in its semiconductor business for the first time in 2021 to stabilize its memory chip production capacity and expand its foundry business.   Samsung said in October 2020 that it expects total investment in its semiconductor business to reach 28.9 trillion
[Embedded]
DHT11 and DS18B20 temperature and humidity control microcontroller program
Based on 51 single chip microcomputer, the sensor uses dht11 and ds18b20. The temperature measurement accuracy of dht11 is limited, and 18b20 can make up for it. The first line shows the humidity and temperature collected by dht11, as well as the relay status. The second line shows the temperature and THI collected by
[Microcontroller]
DHT11 and DS18B20 temperature and humidity control microcontroller program
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号