0 Introduction
Taking the intelligent system of electronic equipment fault inspection and repair skill assessment and training as an example, this paper introduces a master-slave network communication system composed of a PC and multiple single-chip microcomputers. The single-chip microcomputer control is the lower computer, responsible for data collection and control of the fault point of the electronic equipment, and transmits the results to the PC through the interface; the PC is the upper computer, which analyzes and processes the data and controls the operation of the single-chip microcomputer according to the results of analysis and processing. At present, there are usually four communication methods for using Visual C++ to develop serial communication to realize intelligent assessment and training systems:
(1) Calling API (Application Program Interface) function to implement;
(2) Using Visual C++ standard communication functions such as inp and inpw to directly operate the serial port;
(3) Using Visual C++ communication controls (MSComm);
(4) Using communication classes written by third parties (Cserial).
Among the above methods, the first method is widely used, but it requires many low-level settings, is relatively complex, requires a high degree of specialization, and is difficult to use; the second method requires understanding the principles of hardware circuit structure and is difficult to master; the third method seems simpler and only requires simple configuration of the serial port, but uses the confusing WARIANT class and cannot meet the needs of using multiple serial ports for complex processing; the fourth method is to use a CSerial class specifically for serial communication. This method is powerful and can be used conveniently as long as you understand several member functions of this class. The RS 485 bus is widely used in network microcontroller systems for its advantages of good flexibility, low cost, strong anti-interference ability, multiple supported nodes, long transmission distance, and simple connection. In this system, the host computer uses the Cserial class communication method of Visual C++; the lower computer uses the AT89C52 microcontroller of ATMEL, and the bus uses the RS 485 standard networking.
l System structure
The whole system is a master-slave bus monitoring system based on RS 485 field bus, custom communication protocol, connecting each lower computer and upper computer on the bus, and managed by the upper computer. The system includes monitoring layer, communication layer, and field equipment layer. Among them, the monitoring layer is undertaken by the upper computer (PC), which is responsible for receiving data uploaded by the underlying field equipment, analyzing and storing data, setting and modifying the parameters of the lower computer, and querying real-time and historical data to realize the monitoring and management of field equipment; the communication layer communicates with the field lower computer equipment in real time through a self-defined communication protocol to complete the packaging, unpacking, inspection and other processing of data communication packages; the field equipment layer is a monitoring system composed of multiple electronic devices, single-chip microcomputers, relays, keyboards, LCD displays, etc.
The system structure block diagram is shown in Figure 1.
The upper computer is a teaching control management system operated by teachers, and its functions are realized by programming with Visual C++ on a microcomputer. The main functions of the teaching control management system are:
(1) technical preparation for the examination;
(2) invigilation of the examination;
(3) assisting in completing other examination information management tasks.
According to the functional requirements, the teaching control management system consists of a communication module, a code compilation module, a code execution module, a system management module, and a historical data query module. These modules and the user interface together constitute the entire system software.
The lower computer, as the student client of this distributed control system, is an application system based on the AT89C52 single-chip microcomputer. This system uses a monitoring system composed of computers, AT89C52 single-chip microcomputers, optocouplers, drive circuits, relays, color TVs, etc., through a local area network to form an intelligent training and identification system. The AT89C52 single-chip microcomputer control system is shown in Figure 2. [page]
The AT89C52 single-chip microcomputer control system adopts a master-slave system composed of a variety of microprocessor chips composed of computers and AT89C52 single-chip microcomputers. The teacher computer is the upper computer of the system, which realizes human-computer interaction and data exchange, retrieval, storage, processing, updating of graphic display, control and communication of the lower computer (i.e., student computer). The student computer completes data collection and signal processing. The teacher computer is the host computer and the student computer is the slave computer. The communication method between the master and the slave computer adopts the serial port method. Each training or identification station has an independent student computer and color TV, and each student computer is interconnected by a network cable. The student computer controls the state of the color TV fault point through a relay.
The AT89C52 single-chip microcomputer control system requires software and hardware development. Unlike a single independent single-chip microcomputer system, the single-chip microcomputer in the network not only needs to work according to the pre-designed program, but more often needs to adjust the working program in time according to the control instructions from the upper computer. The main functions of the lower computer during practical training or examinations are as follows:
(1) Serving as a terminal for the upper computer;
(2) Serving as an electronic equipment controller;
(3) Providing an interactive interface for candidates;
(4) Other invigilation services.
2 Communication interface design
The communication interface is an important part of the single-chip control system. The single-chip computer and the computer are constantly exchanging and transmitting information, and this information exchange and transmission must be realized through the communication interface and data bus. The reasonable selection of communication interface devices and buses is the premise and guarantee for the smooth data exchange and transmission in the single-chip control system.
The system adopts RS 485 bus networking. The host computer converts the RS 232 standard level to the RS 485 standard level through the serial interface via the standard RS 232 bus and RS 232/RS 485 converter to communicate with the candidate's lower computer end; on the lower computer end, SN75176 converts the RS 485 standard level to the TTL level to access the asynchronous serial communication port (UART) of the processor, realizing half-duplex communication of the RS 485 network.
The RS 232/RS 485 converter uses plug-and-play products on the market, which has realized intelligent control of transceiver enablement, without changing any host computer hardware. The upper computer can connect to up to 32 lower computers. If SN75184 is used on the lower computer side, the upper computer can connect to up to 64 lower computers.
The design of the RS 485 interface circuit should fully consider various interferences on the line and the matching of the line characteristic impedance. During the transmission process, electromagnetic interference and terminal reflection will be generated, causing the useful signal and the interference signal to be superimposed on the transmission line. When the interference is too large, communication cannot be carried out. The system uses the SN75176 RS 485 interface chip. The communication medium of the RS 485 bus network uses a twisted pair with a shielded layer, and a 120Ω matching resistor is installed at each end of the transmission line to eliminate the reflection of the signal on the transmission line. The communication distance can reach 1200 m.
3 Communication protocol
The software design of RS 485 interface has a great influence on the reliability of system networking. Since RS 485 bus is an asynchronous half-duplex communication bus, the bus can only present one state at a certain moment, so this method is used for query communication between the upper computer and the lower computer. In order to coordinate the time-sharing multiplexing of the bus, a reasonable communication protocol must be formulated to ensure the normal data communication. The communication protocol of this system is: the baud rate is agreed to be 9600 b/s, Tl works in mode 2, the initial value is FDH, SMOD=0. The serial port is initialized to mode 3. The communication format requirements are as follows: The
communication data format is a total of 24 bits (binary), 8 bits of identification code, 8 bits of control instruction code, and 8 bits of fault point code. The format is as follows:
The regulations are as follows:
The identification code is the lower computer address code, and the address range is 70H to 88H. The control instruction code is: the character "1" indicates that the fault point is short-circuited, and the ASCII code is "31H"; the character "O" indicates that the fault point is disconnected, and the ASCII code is "30H".
(1) Upper computer status word:
bo: Paper issuing instruction flag 1, no paper issuing instruction flag 0;
b1: Test start instruction flag 1, no test start instruction flag O;
b2: Answer query instruction flag 1, no answer query instruction flag 0;
b3: Forced question termination instruction flag 1, no forced question termination instruction flag O;
b4: Resume question execution instruction flag 1, no resume question execution instruction flag 0.
[page]
(2) Status word of the lower computer:
b0: Login request 1, no login request 0;
b1: Logged in status flag 1, not logged in status flag 0;
b2: Paper collected status flag 1, not collected status flag 0;
b3: Start answering status flag 1, not started answering status flag O;
b4: Paper submission request flag 1, no paper submission request flag 0;
b5: Paper submitted flag 1, not submitted flag O;
b6: Question answering suspension flag 1, question answering resumption flag O.
4 Communication process
The upper computer starts the program and enters the polling process. At this time, the lower computer starts and logs in. When it is polled, it sends a login message. After the upper computer receives it, it performs the necessary login processing. After all the lower computers have logged in or the invigilator believes that the login information of all candidates has been received, the paper distribution button is pressed to distribute the papers to each logged-in lower computer in turn. After the papers are distributed, the invigilator presses the start button and broadcasts the start command of the exam. The lower computer displays the exam questions and the system starts timing. During the exam, the invigilator can query the status of any lower computer (including the exam status of the candidates); even the automatic inspection command can be started to automatically inspect the answering status of each candidate. During the exam, the candidate can hand in the paper after answering the questions. After the candidate presses the paper submission button, the paper submission information is sent, and the upper computer receives it and sends a reply message of correct reception. During the exam, if the invigilator finds that a student is cheating, he can press the stop exam button at any time to stop the operation of this lower computer and record zero points for the exam. When the exam time is up, the system automatically determines whether there are still candidates who have not handed in their papers, stops the candidates from answering the papers, and retrieves the answer information from the corresponding lower computer. The basic polling and communication action diagram between the upper and lower computers is shown in Figure 3.
The communication process between the upper and lower computers is as follows:
① The upper computer, as the network master, polls at a certain time interval dtl. The polling process is as follows: First, the upper computer queries the upper computer status word to determine whether there is a communication request. If not, it will issue a communication authorization mark to the polled lower computer. If the lower computer does not respond after a short delay, the lower computer at this address is not online, and the polling is terminated; if there is a response, the channel mark for communicating with this lower computer is set.
② The lower computer issues a command: indicating that the lower computer replies to the query command and determines the status of the lower computer according to the status word. ③ The upper computer issues a command: indicating that
the upper computer sends the upper computer to receive information according to the status word of the lower computer and the status word of the upper computer, according to the principle that the upper computer has priority.
④ The lower computer issues a command: The upper computer parses the data according to the functional command, completes the corresponding display and confirms the reply.
⑤ The upper computer issues a command: When an error occurs during the information transmission process from the lower computer to the upper computer, the upper computer will issue a retransmission function command to the lower computer. The number of retransmissions is determined according to the debugging process.
When designing RS 485 communication software, attention should be paid to the software programming of the RS 485 control end. In order to ensure reliable data transmission and reception, an appropriate delay needs to be added when the RS 485 bus state switches. The delay is generally controlled at about 1 ms before data transmission and reception. After this treatment, the bus has a stable working process when the state switches.
5 Design of host computer communication software
Host computer communication is designed using a CSerial class specifically for serial communication. This method is powerful and can be easily used as long as you understand several member functions of this class. The following are several commonly used member functions:
[page]
6 Conclusion
A software and hardware design based on the AT89C52 single-chip microcomputer network communication system is proposed. The solution has been successfully applied to the intelligent assessment system of electronic product fault repair skills and has been commercialized. After more than a year of use, it has been running reliably. In addition, since the system adopts a modular design and has strong flexibility, it can control terminal devices of different models, brands and functions according to the actual needs of users. Therefore, it has high application value and promotion value.
Previous article:Design of SD card reading and writing system based on single chip microcomputer and FAT16
Next article:Design and implementation of a simple infrared remote control password lock based on single chip microcomputer
Recommended ReadingLatest update time:2024-11-16 15:28
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
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
- PCB circuit board heat dissipation
- PCB board design method and key points analysis
- EEWORLD University - Write a container from scratch
- Thank you +EEWORLD community
- Ask a question about ADC selection
- GD32E231 DIY Contest (5) - Complete the driver and settings of DS1302 and the recognition of long and short keys
- Share the troubleshooting of using bq34z100 chip
- The salary and development path of hardware engineers
- Here are some questions about the differential signal amplifier circuit
- How to Meet the Testing Challenges of Multi-Antenna Systems