Design of temperature acquisition system based on STC89C52 microcontroller and DS18B20 temperature sensor

Publisher:咖啡狐狸Latest update time:2023-07-19 Source: elecfansKeywords:STC89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

With the rapid development of modern information technology, data collection technology is also constantly developing and plays an important role in information technology. Whether data is collected timely and accurately and how the data is collected have become the focus of attention. With the continuous development of embedded technology, various data acquisition systems are continuously used in various fields. Temperature collection is used in smart homes, industrial control, smart agriculture, etc. The lower computer of this temperature acquisition system uses the STC89C52 microcontroller as the main controller and the DS18B20 temperature sensor to collect the temperature. The upper computer uses VB to write programs, collect data through the serial port, store it in the Access database, and display the temperature change curve on the interface in real time.


1 Overall design of the system

The overall block diagram of this temperature acquisition system is shown in Figure 1. The lower computer of the system, the single-chip microcomputer system, uses a ready-made development board. The development board comes with a DS18B20 temperature sensor. The development board also comes with a temperature sensor that can maintain the normal operation of the single-chip computer. Peripheral circuits; Microsoft Visual Basic 6.0 Chinese version integrated development environment and Microsoft Office Access 2003 database development software used in the host computer.

Design of temperature acquisition system based on STC89C52 microcontroller and DS18B20 temperature sensor

2 Design and implementation of host computer

The main difficulty in the design of the host computer is that the serial port receives data from the host computer and sends the data to the database and displays the data with curves in real time. The overall design flow chart of the host computer is shown in Figure 2.

The Mscomm32.ocx control is mainly used to receive data from the serial port. To add this control in Microsoft Visual Basic 6.0, you need to set the COM port (modifiable), baud rate (9600), data bit (8), stop bit (1), calibration Check bit (0), etc., receive data through OnComm() event-driven method.


The database uses Microsoft Office Access 2003. The database must be established first. The established database is shown in Figure 3. It has 4 fields, namely number, temperature, collection date, and collection time. The corresponding data types are automatic number, number, Text, text.

To operate the database Access programmatically in Microsoft Visual Basic 6.0, first connect the data source, then open the database and set up the corresponding data operations, then update the database, and finally close the database. In the actual operation, the control Adodc is connected to the control Datagrid. , to connect the data source with the interface display.


2.1 Main design steps

1) First create a new EXE project in the VB development environment, and then place some necessary controls on the form, such as button (Command) controls, text boxes (Textbox), etc.;

2) Add Microsoft conmm control 6.0, Microsoft datagrid control 6.0 and Microsoft ADO data control 6.0 to these three controls in the added components;

3) Create a new database in the database software and create a new table temp;

4) Connect to the database Access and test whether the connection is successful;

5) Connect Adodc to Datagrid to connect data sources and interface display;

6) The corresponding functions can be realized by linking the Command button with the search, deletion, modification and addition of the database;

7) Realize the drawing function through the picturebox control;

8) Connect the serial port data with the database and picturebox control.

2.2 Host computer programming (program segment)

2.2.1 Serial port processing program

2.2.2 Write data to the database

3 Design and implementation of slave computer

3.1 Hardware and principles of slave computer

The lower computer of the temperature acquisition system uses the STC89C52 microcontroller as the main controller and the DS18B20 temperature sensor to collect the temperature. The hardware circuit diagram is shown in Figure 4.

STC89C52 microcontroller has:

1) It is a derivative of the MCS-51 series of microcontrollers. It is fully compatible with the standard 8052 microcontroller in terms of instruction system, hardware structure and on-chip resources. The DIP40 package series is Pin-to-Pin compatible with the 8051, making it easy to master when using it;

2) High speed (maximum clock frequency 90 MHz), low power consumption, low price, stable and reliable, widely used, highly versatile, programmable in the system/application (ISP, IAP), and does not occupy user resources. This system uses 1 interrupt, 2 timers and 4 ports P0~P3 of the STC89C52 microcontroller. An external 11.059 2 MHz crystal oscillator is used, and a 30 pF capacitor is used to ground to improve the stability and reliability of the system.


DS18B20 has: 1) Only one I/O port is required to achieve communication; 2) Each device in DS18B20 has a unique serial number; 3) In actual applications, temperature measurement can be achieved without any external components. ; 4) The measurement temperature range is between -55 ~ 125°C; 5) The resolution of the digital thermometer can be selected by the user from 9 to 12 digits; 6) There are internal upper and lower temperature limit alarm settings.


How to use DS18B20: DS18B20 uses the 1-Wire bus protocol. For the microcontroller STC89C52, we must use software methods to simulate the single-bus protocol timing to complete access to the DS18B20 chip. Since DS18B20 reads and writes data on an I/O line, it has strict timing requirements for the data bits read and written. DS18B20 has a strict communication protocol to ensure the correctness and integrity of data transmission. The protocol defines the timing of several signals: initialization timing, read timing, and write timing. All timings use the host as the master device and the single-bus device as the slave device. Each command and data transmission starts when the host actively initiates the write sequence. If the single-bus device is required to send back data, after the write command is issued, the host needs to initiate the read sequence to complete the data reception. Data and commands are transmitted low-end first.


3.2 Software design

The focus of the software design is to collect the temperature and send the collected temperature correctly through the serial port. The software design flow chart is shown in Figure 5.

The software begins to initialize various ports, timers, serial ports, etc., and determines whether an interrupt is generated. If it receives an If the interval is reached, start collecting the temperature and send the data, otherwise continue to determine whether an interrupt is generated.

4 test results

Figure 6 is a rendering of the actual operation of this temperature acquisition system.

5 Conclusion and prospects

This temperature acquisition system can collect the data collected by the DS18B20 temperature sensor through the microcontroller, and transmit it to the host computer in real time using the serial port; the host computer has the ability to receive data in real time, and store the data received in real time into the Access database; it can real-time The temperature curve can be displayed on the interface accurately; the database has four attributes: number, date, time and temperature; the database has the functions of searching, modifying, deleting, adding and searching the first record, next record, previous record and last record; it can Record start time, end time and time difference; display current time and date.

Keywords:STC89C52 Reference address:Design of temperature acquisition system based on STC89C52 microcontroller and DS18B20 temperature sensor

Previous article:Use 51 microcontroller to write an electric small fan solution
Next article:Design of STC8H8K64U microcontroller compatible with STC89C52 development board

Latest Microcontroller Articles
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号