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.
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
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Weak Signal Processing Theory (Edited by Tang Songyuan, Yang Jian, and Ai Danni)
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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Analysis of the interrupt process of C6000 DSP system
- How to select a display detector
- [Zero-knowledge ESP8266 Tutorial] Zero-knowledge WIFI Tutorial - http WEB Server Example
- 【DIY fan】Unboxing
- FOC vacuum cleaner, low voltage sensorless FOC solution, main control chip CMS32M5733Q048
- Several basic knowledge of MCU, must-read for beginners
- There are two problems when using the ST motor library
- MSP430 interrupt mechanism
- Current sensing resistors in lithium-ion battery formation and capacity test equipment
- How to completely shut down Pmos