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, the distributed intelligent control system that uses PCs as host computers to implement user control and single-chip microcomputers as slave computers for real-time data acquisition undoubtedly has a good application prospect. 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 through the serial port.
l Hardware foundation of data acquisition system
The lower computer of this system selects Atreel's AT89S51 single-chip microcomputer as the control core, which is responsible for collecting on-site temperature values. The temperature sensor converts the temperature into a voltage signal, which is converted into an 8-bit digital value through the analog/digital converter ADC0809, and is stored in the single-chip microcomputer 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. It gives full play to the advantages of the single-chip microcomputer in real-time data acquisition and the PC in graphics processing, display and database management. The application of single-chip microcomputers 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 single-chip microcomputer TTL level into RS 232 level, forming a system structure block diagram as shown in Figure 1.
2 Implementation of serial communication under 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
MSComm control is a serial communication ActiveX control provided by Microsoft. MSComm control sends and receives data through the serial port and provides serial communication functions for applications. The main properties of MS-Comm communication control are as follows:
(1) 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) Settings property is used to set initialization parameters. Set or return four parameters such as online rate, parity, data bits, and stop bits in the form of a string. Its format is: "BBBB, P, D, S". Among them, BBBB represents the online rate; P represents the parity bit check mode; D represents the number of data bits; S represents the number of stop bits. The 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 opening the serial port; when the value is False, it means closing the serial port and clearing 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 Upper computer program design
The upper computer is mainly responsible for sending control commands, as well as data reception, processing, calculation, data display and other functions. The upper computer program is divided into four parts: interface design, program initialization, data communication, and data processing. The program flow is shown in Figure 2. [page]
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 the 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 the 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 of 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 represent that the temperature value exceeds the limit range.
After entering the main interface, the user first clicks "Start Contact", at which time the upper computer will send a contact signal to the lower computer. After receiving the preset contact signal, the lower computer will send the data; then click the "Receive Data" command, and the received data will be displayed in the MSFlexGrid control in order; before processing the data, the user can set the temperature limit according to his own needs, and only click the "Boundary Setting" command to achieve it; finally, after processing the data, click 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
This program consists of data sending (communication signal) and data receiving. The two parts of the program are written under the Click events of the corresponding command buttons "Start Communication" and "Receive Data". The specific program code is as follows:
[page]
3 Design of communication software for lower computer
The lower computer program includes initialization part, data acquisition and receiving contact signal part, and data sending part.
The serial communication of AT89S51 microcontroller uses timer Tl as baud rate generator, and its baud rate is consistent with that of PC. The data transmission format is 8 data bits and 1 stop bit. The query mode is used to send and receive data, timer T1 is set to working mode 2, and the serial port is set to working mode 1. This design sets the communication rate to 9600 b/s, SMOD=0, and the crystal oscillator frequency of the microcontroller is 11.0592 MHz. At this time, the initial value of timer T1 should be set to:
3.1 Receiving command program of upper computer
Receiving command program of upper computer:
3.2 Data sending program
Data sending program:
4 Conclusion
The communication between microcontroller and upper computer is widely used in industrial control sites. Using the communication control MSComm provided by VB to program the upper computer is simpler and more flexible than using API function programming. This paper analyzes the communication method between computer and microcontroller through specific examples. The debugging results prove that the scheme is feasible, can ensure the stability of communication, and has important practical significance.
Previous article:Temperature Recording System Based on Single Chip Microcomputer
Next article:Industrial control system based on 51 single chip
- Popular Resources
- Popular amplifiers
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
- FPGA error, added clock timing, and how to solve this error
- [Project source code] FPGA-based Gigabit Ethernet module UDP design example program
- Here it comes! Summary of 2021 National College Entrance Examination Essay Questions
- LE Audio audio sharing will stimulate a new wave of audio innovation
- Understanding IGBT Drivers in One Article
- A question of the direction of energy transmission
- Interview experience of Texas Instruments Reliability Engineer in Fall 2018
- What factors are related to the communication distance? Why is the module communication distance different from what the manufacturer advertises?
- Show off the goods + MIMXRT1010-EVK show off
- [GD32L233C-START Review] Chapter 5 Dynamic Scanning to Directly Drive 4-Bit Clock Digital Tube