Design of temperature measurement and control system based on VB and MCS-51 single chip microcomputer

Publisher:dadigtLatest update time:2010-06-11 Source: 现代电子技术 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0 Introduction

In modern measurement and control systems, since PCs have powerful data processing capabilities and good user interaction interfaces, and single-chip microcomputers have strong on-site anti-interference capabilities and good cost-effectiveness, distributed intelligent control systems that use PCs as host computers to implement user control and single-chip microcomputers as slave computers for real-time data acquisition undoubtedly have good application prospects. In this article, the single-chip microcomputer realizes temperature detection with good real-time performance; the PC completes data display, storage and statistical analysis, draws real-time temperature curves, and makes judgments on the current status of the system. The two communicate with each other via serial ports.

1 Hardware foundation of data acquisition system

The lower computer of this system uses Atreel's AT89S51 microcontroller as the control core, which is responsible for collecting the temperature value on site. The temperature sensor converts the temperature into a voltage signal, which is converted into an 8-bit digital quantity through the analog/digital converter ADC0809 and stored in the microcontroller through the P1 port of AT89S51. The upper PC communicates with the lower computer through the serial port, sends control commands to the lower computer, receives data uploaded by the lower computer, and performs human-computer interaction. The upper computer uses VB 6.0 to design the human-computer interaction interface, and uses its MSComm control to achieve simple and efficient serial communication with the lower computer. The advantages of the microcontroller in real-time data acquisition and the PC in graphics processing, display and database management are fully utilized. The application of the microcontroller is no longer limited to automatic monitoring or control in the traditional sense, but has formed a development trend of distributed multi-point systems with the network as the core. Since the working levels of the serial ports of the upper and lower computers are inconsistent, the MAX232 chip is used to convert the TTL level of the microcontroller into the RS 232 level, forming a system structure diagram as shown in Figure 1.

2 Implementation Method of Serial Communication in VB Environment

The design style of VB visual interface is simple, easy to learn and efficient. It has become a tool adopted by many developers and is widely used in various fields. VB's MSComm communication control only requires users to write a small amount of program code to complete the development process of communication software.

2.1 Introduction to MSComm Control

The MSComm control is a serial communication ActiveX control provided by Microsoft. The MSComm control sends and receives data through the serial port, providing serial communication functions for applications. The main properties of the MS-Comm communication control are as follows:

(1) The CommPort property is used to set or return the communication connection port. During design, the CommPort property value can be set to any number from 1 to 16 (the default value is 1).
(2) The Settings property is used to set initialization parameters. It sets or returns four parameters, including the online rate, parity check, data bits, and stop bits, in the form of a string. The format is: "BBBB, P, D, S". Among them, BBBB represents the online rate; P represents the parity check mode; D represents the number of data bits; S represents the number of stop bits. This system sets it to "9600, N, 8, l".
(3) The Portopen property is used to set or return the status of the communication serial port (on or off). The Portopen property is of Boolean type. When the value is True, it means to open the serial port; when the value is False, it means to close the serial port and clear the receive and send buffers.
(4) The Input property is used to read data from the receive buffer.
(5) The Output property is used to write data to the send buffer.
(6) The InputMode property is used to read or set the format of data read from the receive buffer. When InputMode=0, the data is read in text form; when InputMode=1, the data is read in binary form.

2.2 Host computer program design

The host computer is mainly responsible for sending control commands, as well as receiving, processing, calculating, and displaying data. The host computer program is divided into four parts: interface design, program initialization, data communication, and data processing. The program flow is shown in Figure 2.


The main operation interface is mainly divided into four components, as shown in Figure 3. To make the interface clear, use frame controls to separate them.


Among them, the temperature limit part is mainly used to display the upper and lower limits of temperature set by the user; the data receiving part uses the external control MSFlexGrid to display the data that has been received; the statistical calculation part is used to display the results of data analysis, such as maximum value, minimum value, average value, etc., and finally make a comprehensive judgment on the current system status; the temperature curve part displays the changes of all current temperatures, and each temperature value corresponds to a prominent point on the curve. The points within the two dotted lines represent that the temperature value is within the limit range, and the two points outside the two dotted lines indicate that the temperature value exceeds the limit range.

After entering the main interface, the user first clicks "Start Communication", at which point the upper computer will send a communication signal to the lower computer. After receiving the preset communication signal, the lower computer will send the data over; then click the "Receive Data" command, and the received data will be displayed in the MSFlexGrid control in sequence; before processing the data, the user can set the temperature limit according to their own needs, which can be achieved by simply clicking the "Limit Setting" command; finally, after processing the data and clicking the corresponding command button, the current temperature curve will be drawn on the interface, and various statistical parameters will be calculated.

2.3 Serial communication initialization program

This program is mainly used to initialize the data buffer and serial port, such as serial port selection, serial port data format, etc. The code of this part of the program is as follows:

2.4 Host computer communication program

The program consists of data sending (contact signal) and data receiving. The two parts of the program are written under the Click events of the corresponding command buttons "Start Contact" and "Receive Data". The specific program code is as follows:

3. Design of communication software for lower computer

The lower computer program includes the initialization part, the data acquisition and receiving communication signal part, and the data sending part.

The AT89S51 microcontroller serial communication uses timer T1 as a baud rate generator, and its baud rate is consistent with that of the PC. The data transmission format is 8 data bits and 1 stop bit. The query method is used to send and receive data, timer T1 is set to work mode 2, and the serial port is set to work mode 1. This design sets the communication rate to 9600 b/s, SMOD=0, and the microcontroller crystal oscillator frequency is 11.0592 MHz. At this time, the initial value of timer T1 should be set to:

3.1 Receiving command program from host computer

Receive command program from host computer:

3.2 Data sending procedure

Data sending procedure:



4 Conclusion

The communication between the microcontroller and the host computer is widely used in industrial control sites. Using the communication control MSComm provided by VB to program the host computer is simpler and more flexible than using API functions. This article analyzes the communication method between the computer and the microcontroller through a specific example. The debugging results prove that the scheme is feasible and can ensure the stability of communication, which has important practical significance.

Reference address:Design of temperature measurement and control system based on VB and MCS-51 single chip microcomputer

Previous article:Design of multi-parameter real-time acquisition and processing system controlled by single chip microcomputer
Next article:Design of triple-speed sampling method for PIC software serial asynchronous communication

Recommended ReadingLatest update time:2024-11-16 22:26

AT89S51 Parallel I/O Port
      The AT89S51 microcontroller has a total of 4 bidirectional 8-bit parallel I/O ports, denoted as PO, Pl, P2 and P3, among which the output latch belongs to the special function register. Each bit of the port is composed of an output latch, an output driver and an input buffer. In addition to byte input/output, th
[Microcontroller]
AT89S51 Parallel I/O Port
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号