Multiple DS18B20 circuit detection and temperature display on a single line

Publisher:Serene123Latest update time:2016-10-19 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Project: Multiple DS18B20 circuit detection and temperature display on a single line

'Result: The proteus simulation runs successfully, and the temperature is displayed in a loop. Theoretically, no matter how many DS18B20 are hung, it will work.
 

$regfile = "m16def.dat"
$crystal = 3276800
Baud = 9600
Declare Sub Screen()

Config 1wire = Portd.7 'Define single bus interface
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Porta.1 , Rs = Porta.0 'Define LCD interface
Config Lcd = 16 * 2 'Define LCD type as 1602
Cls
Cursor Off 'Turn off cursor display

Dim Romdat(8) As Byte
Dim Romadd As Byte
Dim T(2) As Byte
Dim Wd As Word
Dim Temp As Single
Dim A As Byte
Dim M As Byte
Dim N As Byte
Dim I As Byte
Screen
Lcd "Welcome to"
Locate 2, 2: Lcd " http://ycavr.cn "
Wait 2
Screen
1 wreset
If Err = 0 Then 'If there is a DS18B20 on the bus, then detect the temperature and display it. If there is no DS18B20, then end the program.
   Lcd "DS18B20 OK!"
Else
   Lcd "ERROR !"
   End End
If

Romadd = 1
Romdat(1) = 1wsearchfirst() 'Find the first device
For N = 1 To 8
   Writeeeprom Romdat(N), Romadd
   Incr Romadd
Next

Do
   Romdat(1) = 1wsearchnext() 'Search for the next one until all are found.
   For N = 1 To 8
      Writeeeprom Romdat(N), Romadd 'Write the ROM address to the EEPROM
      Incr Romadd
   Next
Loop Until Err = 1
I = 1wirecount() 'Return the number of DS18B20 on the bus
Screen
Lcd "Found " ; I ; " Sensors" 'Show the number of DS18B20
Wait 1

Do
   Romadd = 1
1 wreset
1 wwrite &HCC 'Skip ROM match
1 wwrite &H44 'Start temperature conversion'Waitms
   20
   For M = 1 To I
      Screen
      Lcd "No. " ; M
      For N = 1 To 8
         Readeeprom Romdat(N), Romadd
         Incr Romadd
      Next

1      wreset
1      wwrite &H55                                          'ROM匹配
      For N = 1 To 8
1         wwrite Romdat(N)
      Next
1      wwrite &HBE                                          '读转换温度
      For N = 1 To 2
         T(n) = 1wread()
      Next
      Wd = T(2) * 255
      Wd = Wd + T(1)
      Locate 2, 1
      If T(2) > 15 Then
         Lcd "T= -"
         Wd = Not Wd
         Incr Wd
      Else
         Lcd "T= +"
      End If
      Temp = Wd / 16
      Lcd Temp ; " C "
      Print M; Temp
      Wait 2
   Next
Loop
End

Sub Screen()
Local J As Byte
For J = 1 To 16
   Locate 1, J: Lcd "*"
   Locate 2, J: Lcd "*"
   Waitms 30
Next
For J = 16 To 1 Step -1
   Locate 1, J: Lcd " "
   Locate 2, J: Lcd " "
   Waitms 30
Next
Home
End Sub

Reference address:Multiple DS18B20 circuit detection and temperature display on a single line

Previous article:A concise frequency counter and clock program
Next article:Based on M8 Marquee Program

Recommended ReadingLatest update time:2024-11-17 05:34

Design of two DS18B20 temperature sensors based on 51 single chip microcomputer
This paper proposes a design scheme of a two-way temperature controller based on a 51 single-chip microcomputer. The design scheme uses two DS18B20 temperature sensors to collect the temperature of two different places, and processes it through AT89C51. The measured temperature is displayed by a four-digit LED digital
[Microcontroller]
Design of two DS18B20 temperature sensors based on 51 single chip microcomputer
MCU temperature detection alarm program (ds18b20)
The program uses the digital temperature acquisition chip ds18b20 to obtain a temperature resolution of 12 bits. The program can obtain a lower resolution temperature. ds18b20 has only three i/o interfaces, two of which are power pins and one is a data bus. Only one line is needed for communication. Distributed temper
[Microcontroller]
Design of household temperature measuring device based on DS18B20
1. Design Overview This design uses the USB port as the power supply port, uses the DS18B20 temperature sensor to collect temperature information, uses the AT89C2051 single-chip microcomputer for control, and uses a four-digit common anode digital tube display to achieve temperature measurement and display (the
[Test Measurement]
Design of household temperature measuring device based on DS18B20
Single chip perpetual calendar (LCD12864, DS18B20, DS1302)
1. Introduction This circuit consists of AT89C51 minimum circuit board, LCD12864 display module, DS18B20 temperature module and DS1302 clock module. The main functions are: display real time and current temperature. 2. Operation Effect 3. Partial Code /*Want more projects private wo!!!*/ #include reg51.h #inclu
[Microcontroller]
Single chip perpetual calendar (LCD12864, DS18B20, DS1302)
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号