Design of temperature monitoring system based on single chip microcomputer and PC

Single chip microcomputer STM32L151CCU6
MOS power IC full range
Mobile phone crystal 3.2*2.5mm 3225 26M (26.000MHZ) 7.5PF 10PPM 20PPM 30PPM
0201 package SLP0603 ESD electrostatic diode 5V one-way ESD
1206RGB (single)

Temperature is an important physical quantity, and it is often necessary to monitor the ambient temperature in industrial and agricultural production and daily life. In this paper, a temperature monitoring system is designed. The temperature sensor adopts DS18B20, and the lower computer adopts AT89S52 single-chip microcomputer to realize functions of temperature measurement, display and over-limit alarm. The upper computer adopts PC, and uses Matlab to design a friendly human-computer interaction interface to realize temperature. Capture, display, plot, alarm, save data and more.

1 overall system design

The system adopts AT89S52 single-chip microcomputer as the lower computer and PC as the upper computer. The two send or receive data through the serial port to realize the functions of ambient temperature measurement, display, over-limit alarm and temperature data storage. The overall design block diagram of the system is shown in Figure 1.

基于单片机与PC机的温度监测系统设计阐述0

The minimum system of the MCU includes the reset circuit, clock circuit and power supply circuit necessary for the operation of the MCU. The temperature sensor adopts DS18B20 chip, the measuring temperature range is -55~+125 °C, the chip does not need external power supply, the programmable resolution is 9~12 digits, the temperature resolution is up to 0.062 5°C, data transmission Only one communication line is needed, and the P2.0 port of the single chip microcomputer is connected. The temperature display part uses 4 eight-segment LED common anode digital tube, adopts dynamic driving mode, digital tube a, b, c, d, e, f, g, DP eight segments from single chip microcomputer P0.0-P0.7 port Control, M1.0 P1.0 - P1.3 port control 4 digital tube rotation dynamic display. The over-limit temperature alarm uses a buzzer, which is controlled by the P2.1 port of the single-chip microcomputer.

The serial port of the PC adopts the standard RS 232 interface, and the serial port level of the MCU is TTL level, which does not match the electrical characteristics of RS 232. Therefore, the system uses the common chip MAX 232 to complete the level conversion. So that the serial port of the MCU can communicate with the RS 232 interface. The upper computer dynamic temperature monitoring system uses Matlab software to design a friendly human-computer interaction interface to realize the functions of setting, collecting, calculating, displaying and saving temperature data.

2 lower computer program design

As the lower computer, the main task of the one-chip computer is:

1) The temperature data is collected and processed by DS18B20, and the current temperature is displayed in real time on the LED digital tube, and one digit after the decimal point is reserved;

2) Receive the upper and lower limit alarm temperature set by the upper computer through the serial port, and display it on the LED digital arm;

3) receiving a command to send temperature data through the serial port, and sending temperature data to the upper computer;

4) Judging the current temperature. If the buzzer alarm is activated beyond the limit, the square wave driving buzzer with different frequencies is set to emit different sounds to distinguish the upper limit from the upper limit.

基于单片机与PC机的温度监测系统设计阐述1

The MCU uses Keil C51 to write the program, the DS18B20 resolution is set to 12 bits, and the main program flow chart is shown in Figure 2. The main program mainly completes the initialization of the system, mainly including the initialization of the DS18B20 and the serial port; the four LED digital tubes display "0000", waiting for the upper computer to send the upper limit temperature data; after receiving the data, waiting for the upper computer to send the lower limit temperature data; receiving the data, The lower limit temperature is displayed and the humidity is measured after a delay of about 2 seconds. Read the DS18B20 temperature value and form the 16-bit unsigned integer temperature data from the lower 8-bit byte and the upper 8-bit byte (the lower 4 bits are the fractional part of the degree, and the middle 8 bits are the integer part of the temperature) , processing the degree data and displaying the temperature value on the digital arm; judging the temperature, over-limit alarm; receiving the command word "255" sent by the upper computer to send the 16-bit temperature data read by the DS18B20 to the upper computer, first sending low 8-bit byte, followed by high 8-bit byte; return to read DS18B20 temperature value.

3 PC programming

PC as the host computer, the main tasks include:

1) Set the upper and lower limit alarm temperature and send it to the lower computer through the serial port;

2) Send a command requesting the MCU to transmit temperature data through the serial port, the command data is "255";

3) Receive the temperature data of the lower computer through the serial port, display the temperature value after various operations, and draw;

4) Judging the current temperature, if the over limit starts the alarm indication and the audible alarm;

5) Save the temperature measurement time and data for future reference.

The upper computer uses Matlab to write programs to realize communication with the lower computer and temperature monitoring. Matlab is a scientific computing software developed by MathWorks. It has powerful numerical calculation and graphic display functions. With Matlab, users can also operate the computer's serial port to communicate with external devices, and support BS-232, RS422 and RS485 interface standards. Matlab has a built-in GUI (Gr aphie UserInterface) module with interface design and development functions. This paper uses MatlabGUI to design the interface of the host computer system. It adopts the M file programming design method, which is more powerful than the GUIDE (Graphical User Interface Development Environment), and the code is easy to modify. The interface for system temperature measurement is shown in Figure 3.

基于单片机与PC机的温度监测系统设计阐述2

The temperature measurement interface retains the menu of the MATLAB form frame window. The menu design function uimenu() is used to design the first level menu About and the second level menu Operation steps and Contact us, which can pop up the window to display the system operation steps and the author's contact information.

Use the text type of the Style property of the function uicontrol() to set the display of the upper and lower limit temperature, the over limit alarm indication, the temperature measurement start and the end time display in the lower left corner of the window, and establish the current, maximum, minimum and average temperatures in the upper right corner of the window. display. Use the function axes() to create a coordinate center axis for drawing a dynamic temperature curve. Use the pushbutton type of the Style property of the function uicontrol() to create 5 buttons in the lower right corner of the window. Edit the Callback callback function for each control to achieve complete PC temperature monitoring.

The "Open Serial Port" button operation mainly completes the serial port initialization, which uses obi=serial('coml', 'baudrate', 9600, 'parity', 'none', 'databits', 8, 'stopbits', 1) The serial port object obj is connected to the serial port com1, the baud rate is set to 9600, no parity is set, the number of data bits to be transmitted is set to 8 bits, and the number of bytes terminated is 1 bit. Then use fopen(obj) to open the serial port object.

The "close serial port" button operation mainly uses the fclose (obj) and delete (obj) statements to complete the release of the serial port.

The "Start Temperature Measurement" button operation is the core of the system software. The fwrite (obj, 255) statement is used to send the command word "255", which requires the lower computer to send temperature data; the fread(obj, 2) statement is used to receive 2 bytes of 16 Bit temperature data, first receive the lower 8 bytes, then receive the upper 8 bytes, the lower 12 bits of the 16-bit data is the temperature data, first determine the temperature is positive and negative, then calculate the current temperature, the maximum and minimum of the accumulated measurement temperature Value and average value, 1 bit after the decimal point is displayed in the data display area in the upper right corner of the interface; use the plot() function in real time according to the current temperature.

Draw the temperature curve; determine whether the temperature is over-limit. If the alarm is exceeded, the current temperature will be red, and the sound () function will be used to sound the alarm. The alarm interface when the temperature exceeds the limit is shown in Figure 4.

基于单片机与PC机的温度监测系统设计阐述3

The "Save Data" button operation opens the file save dialog box, selects the path, saves the temperature measurement data, and measures the temperature. The Matlab save file dialog function uiputfile() is called and saved with the save function. Mat format data.

The operation procedure of the upper computer is to click the "Open Serial Port" button, the user inputs the upper and lower temperature limits of the alarm; click the "Start Temperature Measurement" button to start the temperature measurement. At the end of the temperature measurement, click the "Close Serial Port" button; then click the "Save Data" button, select the save path, enter the file name to save the temperature measurement data and the temperature measurement time; finally click the "Exit" button to close the window and exit the system.

4 Conclusion

The designed dynamic temperature monitoring system based on single-chip microcomputer and PC realizes the temperature display and alarm function in the upper computer and the lower computer respectively. The upper computer also realizes drawing the dynamic temperature curve and saves the data for query. The system utilizes Matlab's powerful numerical calculation, graphic display and port operation functions, and has a friendly human-computer interaction interface to realize dynamic temperature monitoring.

150Mbps WIFI Dongle

A WiFi Dongle is a pocket-size device that connects to your smartphone, tablet or laptop and allows you to access the internet while you`re traveling. It is portable, easy to carry, convenient to use, and very affordable.

150Mbps Wifi Dongle,LTE Dongle, FDD TDD Dongle, LTE WIFI device with sim card

Shenhzhen Tongheng Weichuang Technology Co., Ltd , https://www.thwclte.com