'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
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
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Single-chip microcomputer technology and application - electronic circuit design, simulation and production (edited by Zhou Runjing)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Summary: Advanced IO Operation Software SPI Performance
- Detailed explanation of MSP430F149 serial port receiving and sending program
- 【Evaluation of SGP40】-SGP40 temperature and humidity test
- When choosing crystal oscillators, should we choose imported or domestic ones?
- Does anyone know how to write a DLL for a card reader/writer? Is there any relevant information?
- Still using the burning method to test fabric composition? Now there is a new method.
- How to pair MCU with FPGA to improve system efficiency?
- [National Technology N32G457 Review] 1. Brief review of the first power-on
- Helping to be efficient, green and safe, unlock the secrets of high-quality automotive design with Nexperia!
- The pain of vias, isn’t it just a window opened in the via, how can it cause a short circuit?