This article introduces a communication method between the eView touch screen and the commonly used 51 single-chip microcomputer based on the Modbus communication protocol. This method realizes Modbus communication through C51 programming, is universal on the 51 series of single-chip microcomputers, and has a certain reference value.
In industrial control, it is often necessary to observe the operating status of the system or modify the operating parameters. The touch screen can intuitively and vividly display the operating parameters and operating status, and the system operating parameters can be directly modified through the touch screen, with good human-computer interaction. Single-chip microcomputers are widely used in the field of industrial control, and can form a good human-computer interaction environment in conjunction with touch screens.
For the touch screen to communicate with the microcontroller, it is necessary to write a corresponding communication program for the microcontroller according to the communication protocol used by the touch screen. The Modbus protocol is a protocol introduced by Modicon in the United States that effectively supports communication between controllers and between controllers and other devices via a network (such as Ethernet). This article takes the STC89C51 microcontroller and the eView touch screen of Human-Machine Electronics Co., Ltd. as examples to introduce the development process of its communication program.
1 System Structure
To achieve communication between the touch screen and the single-chip microcomputer, the main problem is to solve the communication protocol. This article uses the open Modbus communication protocol, with the touch screen as the master station and the single-chip microcomputer as the slave station. The eView touch screen itself supports the Modbus communication protocol. If the single-chip microcomputer also supports the Modbus protocol, communication can be carried out. The eView touch screen supports two communication interfaces, RS-232 and RS-485. In the field of industrial control, RS-485 has the advantages of high reliability, long transmission distance, and strong anti-interference ability. Therefore, in this system, the touch screen and the single-chip microcomputer communicate using RS-485 connection, and the transmission rate is set to 9600 kbps. RS-485 signal transmission is a half-duplex transmission mode. The single-chip microcomputer converts the 232 signal into a 485 signal through an RS-232/RS-485 passive converter and connects it to the eView touch screen. Figure 1 is the schematic diagram of the system.
The single-chip control system uses the STC89C51 series single-chip, which integrates the MAX810/STC810 dedicated reset circuit (the original external reset can continue to be retained and is compatible with the Intel 8051 pin). It has the characteristics of strong anti-interference ability, strong encryption, high anti-static (ESD), ultra-low power consumption, and low price. In this system, the touch screen is the upper computer and the single-chip is the lower computer.
2 Modbus protocol
2.1 Introduction to Modbus Protocol
Modbus protocol is a universal language used in electronic controllers. Through this protocol, controllers can communicate with each other and with other devices via a network (such as Ethernet). It has become a universal industrial standard. Control devices produced by different manufacturers can be connected to an industrial network through it for centralized monitoring.
The Modbus protocol defines a message structure that a controller can recognize and use, regardless of the network they communicate through. It describes the process of a controller requesting access to other devices, how to respond to requests from other devices, and how to detect and record errors; it establishes a common format for the message domain structure and content.
When communicating on a Modbus network, the protocol determines that each controller needs to know their device address, identify the message sent by the address, and decide what action to take. If a response is required, the controller will generate feedback information and send it using the Modbus protocol. On other networks, messages containing the Modbus protocol are converted to the frame or packet structure used on this network.
2.2 Modbus RTU communication data transmission mode
When the controller device communicates in RTU mode based on the Modbus protocol, each byte in the message contains two 4-bit hexadecimal characters. The main advantage of this method is that more data can be transmitted than the ASCII method at the same baud rate.
The encoding uses 8-bit binary, hexadecimal numbers 0 to 9 and A to F; each 8-bit field in the message is composed of 2 hexadecimal characters. The organizational structure is as follows:
2.3 Modbus RTU message frame structure
The Modbus RTU message frame structure is as follows:
(1) Address code
The address code is the first byte of the communication transmission. This section indicates that the slave with the address code set by the user will receive the information sent by the host. Each slave has a unique address code. Only slaves that meet the address code can respond and return, and the response and return start with their respective address codes. The address code sent by the host indicates the address of the slave to be sent, and the address code sent by the slave indicates the address of the slave to be returned. Address 0 is used as a broadcast address so that all slave devices can recognize it.
(2) Function code
The function code is the second byte of the communication transmission. The Modbus communication protocol defines the possible code range as 1 to 255 in decimal. Of course, some codes are applicable to all controllers, some are only applicable to certain controllers, and some are reserved for future use. The host sends a request and tells the slave what action to perform through the function code; the slave responds to the request, and the function code sent by the slave is the same as the function code sent from the host, indicating that the slave has responded to the host to operate. If the highest bit of the function code sent by the slave is 1, it means that the slave has not responded to the operation or the transmission is wrong. After the master device application receives a response to the objection, the typical processing is to resend the message. Table 1 lists some of the function codes supported by common Modbus.
Take reading coil status as an example. The master sends the command: [device address] [command number 01] [starting register address high 8 bits] [low 8 bits] [high 8 bits of the number of registers to read] [low 8 bits] [low 8 bits of CRC check] [high 8 bits]. The slave responds: [device address] [command number 01] [number of bytes returned] [data 1] [data 2]… [data n] [low 8 bits of CRC check] [high 8 bits].
(3) Data area
The data area varies according to the function code. The data area contains what action the slave needs to perform, or the return information collected by the slave. This information can be actual values, set points, addresses sent by the host to the slave or by the slave to the host, etc. For example, if the function code tells the slave to read the value of a register, the data area must contain the starting address of the register to be read and the read length. For different slaves, the address and data information are different.
(4) Error Check Code
The host or slave can use the check code to determine whether the received information is wrong. The error detection field contains a 16-bit value (implemented by two 8-bit characters). The content of the error detection field is obtained by performing a "cyclic redundancy check" on the message content. The CRC field is attached to the end of the message, first the low byte and then the high byte, so the high byte of the CRC is the last byte of the message sent. The error check uses the CRC-16 check method.
3 Software Programming
The following is the software written in C5l, which mainly includes CRC check, terminal reception and baud rate setting, etc. Due to limited space, other programs are omitted.
4 Conclusion
Since Modhus protocol has the characteristics of openness and transparency, and 51 series single-chip microcomputer technology is mature and has low development cost, the combination of the two will continue to be the first choice for various communication system designs. This design method has been applied to the communication design between touch screen and single-chip microcomputer, and has achieved good results. This method has a certain reference role in compiling similar communication software, and some programs can be directly transplanted.
Previous article:A digital video mixer based on single chip microcomputer control
Next article:Wireless commentator with touch screen based on STM32
- Popular Resources
- Popular amplifiers
- MathWorks and NXP Collaborate to Launch Model-Based Design Toolbox for Battery Management Systems
- STMicroelectronics' advanced galvanically isolated gate driver STGAP3S provides flexible protection for IGBTs and SiC MOSFETs
- New diaphragm-free solid-state lithium battery technology is launched: the distance between the positive and negative electrodes is less than 0.000001 meters
- [“Source” Observe the Autumn Series] Application and testing of the next generation of semiconductor gallium oxide device photodetectors
- 采用自主设计封装,绝缘电阻显著提高!ROHM开发出更高电压xEV系统的SiC肖特基势垒二极管
- Will GaN replace SiC? PI's disruptive 1700V InnoMux2 is here to demonstrate
- From Isolation to the Third and a Half Generation: Understanding Naxinwei's Gate Driver IC in One Article
- The appeal of 48 V technology: importance, benefits and key factors in system-level applications
- Important breakthrough in recycling of used lithium-ion batteries
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- LM3478 step-down problem
- Does anyone understand the PD power supply protocol? USB Type-C PD power supply problem!
- Which is better, WiFi 6 or 5G?
- Following the privileged classmate video tutorial, lesson 29, the operation went wrong
- Miscellaneous talks on rectification—by maychang
- C2000 MCU implements grid-connected micro solar inverter
- My own feelings about simulation software
- EEWORLD University Hall----RF Amplifier Design Tian Qingcheng, Chinese University, Taiwan
- Pressure sensor/pressure transmitter failure phenomena and solutions
- [National Technology N32G457 Review] 2. Unboxing + Lighting