Abstract: This paper analyzes the basic principle of using serial ports for multi-machine communication in MCS-51 series single-chip microcomputers, studies the network control of traffic light control system by using single-chip multi-machine communication, designs hardware circuit diagram and master and slave programs, and simulates them on Proteus software.
Keywords: single-chip microcomputer; multi-machine communication; traffic light system; control network
Due to the rapid development of microcomputer technology and the complexity of control systems, multi-machine communication is more and more widely used, especially in the control of some industrial processes, multi-machine communication has become the mainstream communication method in the field of communication control.
In view of the fact that the current single-chip microcomputer books (including textbooks) rarely introduce the implementation technology of multi-machine communication, this paper designs a traffic light control network system based on the traffic light control system, and gives a solution for single-chip multi-machine communication as an example.
1 Basic principles of single-chip multi-machine communication
In addition to point-to-point communication, communication between computers also includes one-to-multiple or multi-machine communication, which constitutes a computer network, among which master-slave multi-machine communication is a more commonly used method. In the master-slave multi-machine communication system, there is only one host, but there can be multiple slaves. The information sent by the host can be transmitted to each slave or a designated slave. The information sent by the slave can only be received by the host. The slaves cannot communicate directly with each other. The host is usually a PC, but can also be a single-chip microcomputer (this article studies the use of single-chip microcomputers as hosts). The slaves are usually single-chip microcomputers. Mode 2 and Mode 3 of the serial port of the MCS-51 single-chip microcomputer have multi-machine communication functions, which can realize a multi-machine distributed system consisting of a host and several slaves in a bus-type manner. The connection method is shown in Figure 1.
In multi-machine communication, the multi-machine communication control bit SM2 of the MCS-51 microcontroller can be fully utilized. The SM2 of the microcontroller used as the host should be set to 0, and the SM2 of the microcontroller used as the slave should be set to 1. There are two types of data sent by the host and received by the slave: one is the address, which is used to indicate the address of the slave that needs to communicate with the host, and is marked by the 9th bit of the serial data being "1"; the other is the data, which is marked by the 9th bit of the serial data being "0". Since SM2=1 of all slaves, each slave can always receive the address sent by the host when RI=0 (because the 9th bit of the serial data is "1") and enter its own interrupt service program. In the interrupt service program, each slave compares the received slave address with its local address (assigned during system design). All slaves that are not equal in comparison exit from their respective interrupt service programs (SM2 is still 1), and only slaves with equal comparison addresses are the slaves addressed by the host for communication. The addressed slave sets SM2=0 in the program to receive the data or command (RB8=0) that follows. The above process can be further summarized as follows:
(1) The host's SM2=0, all slaves' SM2=1, are in the listening state (can only receive address frames) to receive the address sent by the host.
(2) When the host sends a frame of address information to the slave, 8 bits are the address, and the 9th bit is 1 to indicate that it is an address frame.
(3) When SM2=1, RB8=1 and RI=0, all slaves receive the slave address frame sent by the host, perform interrupt processing, enter the corresponding interrupt service routine, and compare with the local address to confirm whether it is the addressed slave.
(4) The addressed slave clears SM2 through instructions, sets SM2=0 to enter the data receiving state, can receive the data (including commands) sent by the host, and sends the received slave address back to the host as a response signal for the host to check, thus realizing the dual-machine communication between the host and the addressed slave; the non-addressed slave keeps SM2=1 and exits the interrupt service routine.
(5) Complete the data communication between the host and the addressed slave. After the communication is completed, the addressed slave resets SM2=1, exits the interrupt service program, returns to the listening state, and waits for the next communication.
2 Traffic light control network hardware circuit design
2.1 Hardware circuit
The urban traffic control system is a linkage system. The traffic light control systems of all intersections are controlled by a central host. When an emergency occurs at an intersection (such as traffic control, traffic jam, road maintenance, etc.), clicking the corresponding button of the central host can make all the red lights at the intersection light up and prohibit all ordinary vehicles from passing. This paper uses Proteus software to simulate and design
a master-slave multi-machine system in which one host controls two slaves. When implemented, it can be expanded to 253 hosts. The hardware circuit is shown in Figure 2. The single-chip microcomputer U1 is the host, U2 and U3 are slaves, representing the control machines of the two intersections, S1 and S2 are buttons, connected to P1.1 and P1.0 of U1 respectively. When pressed, the traffic lights of the two intersections are controlled to light up all red lights, indicating that an emergency occurs at the intersection. The two BCD digital tubes connected to the host U1 are used to display the response frame received by the slave, that is, the address number of the intersection where the emergency occurs. If an error occurs in the transmission of the received response frame and it is different from the address number sent by the host, the two digital tubes display FF. When S1 and S2 are not pressed, the two digital tubes also display FF.
Since the "0" or "1" transmitted during serial port communication is distinguished by the voltage relative to the "ground", when using serial port communication, the "ground" lines of the master and slave must be connected so that they have the same voltage reference point.
2.2 Communication Protocol
Multi-machine communication is a complex communication process. There must be a communication protocol to ensure the operability and operation order of multi-machine communication and realize the response and coordination of the sender and receiver. These communication protocols should at least include the address of the slave, the control command of the host, the response frame format of the slave, and the data communication format. The communication protocol of the traffic light control network system established in this paper is
shown in Table 1.
3 Software Program Design
3.1 Host Program Design
The host is mainly responsible for calling the slave, sending control commands, receiving the slave response frame, displaying data, etc. In order to ensure the success of the handshake between the master and the slave, the host uses the query method to send and receive data, and the serial port working mode is set to mode 2, SMOD=0. The flow chart is shown in Figure 3.
3.2 Slave Program Design
The slave runs the traffic light control program in a loop. The traffic light control program uses timer/counter 0 to achieve timing. In order to communicate with the host normally, the serial port of the slave also works in mode 2, SMOD=0, to maintain the same baud rate as the host. Since the address frame and command frame sent by the host when calling the slave are not repeated, in order to make the program simple, this article does not use the ninth bit of data to determine whether it is an address frame or a command frame after the slave receives the data sent by the host. If the received data is equal to the local address, it indicates that it is an address frame, and immediately sends its own address to the host as a response signal; if it is a command, the relevant operation is performed according to the command (all intersections turn red or restore traffic light signals); if it is neither equal to the local address nor one of the two commands, it is considered that the data is not sent to the local machine, and the machine continues to monitor. The list of interrupt service programs for receiving and sending data from the serial port of slave U2 is as follows:
4 Conclusion
It is a relatively complicated process for a single-chip microcomputer to use a serial port for multi-machine communication. Therefore, most single-chip microcomputer books do not introduce this aspect or provide examples. This article discusses the multi-machine communication of the MCS-51 single-chip microcomputer. It is a good example to use single-chip microcomputer multi-machine communication to realize networked centralized control of the urban traffic light control system. Through Proteus simulation operation (its operation is shown in Figure 3), this solution is feasible.
Previous article:Design and implementation of ultrasonic ranging module
Next article:32-segment LCD driver AY0438 and its interface design with single-chip microcomputer
- 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
- Infineon BFP540FESD internal diagram
- 【DFRobot Motor Driver】+ Trial Review
- [Mill MYB-YT507 development board trial experience] Replace Ubuntu 18 firmware
- [Fourth Batch of Shortlist] GigaDevice GD32L233 Review Activity
- ISM330DHCX iNEMO Inertial SiP Module Related Resources
- Xunwei 3399 development board Linux firmware compilation-Debian system compilation and burning
- About the problem of using DMAX's SPI slave mode for transmission
- Making friends through dismantling, review of dismantling articles
- Good luck in resuming work!!!
- TI_C2000 MCU portfolio expands real-time control resources through distributed architecture