Analyze the Remote Measurement and Control System Based on RS485 Bus

Rs-485/'target='_blank'> RS-485 bus remote measurement and control system has been widely used, mainly because rs-485 / 'target = '_blank'> RS-485 bus has a long transmission distance and so on. When the transmission rate is 9600bit/s, the transmission distance can reach 1.2km or more, the maximum transmission rate can reach 10Mbit/s, and only the ordinary twisted pair cable can be used. Up to 256 or more can be connected to the same pair of twisted pair cables. terminal. There are many industrial measurement and control modules that use the RS-485 bus type, such as Adam, Nudan, but the price is higher. This article describes the RS-485 remote measurement and control system combined with the characteristics of the traditional distributed measurement and control system, the use of the characteristics of the RS-485 bus, and clever use of the AT89C2051 microcontroller and CD4067 multi-way switch, thus low cost, flexible functions, easy to use .

Analyze the Remote Measurement and Control System Based on RS485 Bus

1, system design plan

This system consists of a PC as a host and up to 255 AT89C2051 microcontrollers as slaves. The host's RS-232 serial port becomes an RS-485 digital signal bus via an externally inserted RS-232/RS-485 converter. Serial communication between the PC and the microcontroller via the RS-485 digital signal bus.

The serial port of the one-chip computer is changed into RS-485 procedure through MAX485 chip. Microcontroller P1.0 ~ P1.3 used as two pieces

CD4067 (16 select 1 multiplex switch) address selection signal. The two CD4067s together form a dual 16-select 1 multiplexer. The PC first sends out the microcontroller number m (0~254) to be selected, and then sends the serial number n (0~15) of the channel controlled by the single-chip microcomputer. At this time, the nth channel of the mth single-chip microcomputer is selected, and the signal is related to the system. The analog signal bus communicates and is transmitted to the micro data collector attached to the PC parallel port (print port). The miniature data collector carries on the A/D conversion to the analog signal and sends it to the computer for recording and display. If the analog signal of the selected channel is a current signal instead of a voltage signal, a resistor is connected between the analog signal bus to convert the current signal into a voltage signal. In order to effectively transmit relatively weak analog signals, such as thermocouple thermoelectric signals, the system's analog signal bus must use shielded cables. Microdata collectors should use models with multiple range selection and program-controlled amplification to accommodate the output signals of various sensors. This system can also be used to remotely control relays and motors. At this time, the D/A conversion function of the miniature data collector is used. For example, the nth channel of the mth microcontroller is connected to a solid state relay. First, the PC sends an address signal through the serial port to select the channel, and then the PC sends a control signal to the channel through the micro data collector to turn it on or off (through D /A conversion).

2, system hardware design

The RS-232/RS-485 converter and the mini-data collector of the host PC are all available on the market and the price is low. The RS-485 digital signal bus is converted to a TTL-level RS-232 signal via a MAX485 chip to match the serial port of the AT89C2051. P1.0 to P1.3 of the AT89C2051 receive the address selection terminals A0 to A3 of two CD4067 (16-to-1 multiplexers). This causes P1.0 to P1.3 to output a channel number (such as A3A2A1A0=0001). ) When CH1's positive terminal CH1+ (ie, X1 terminal) and CH- (ie, Y1 terminal) are simultaneously strobed. The advantage of using the double-ended signal mode instead of the single-ended signal mode (in which all the negative ends of all channels are common) is that each channel can output signals or receive control signals independently from each other, so that the sensors connected to each channel can share one power supply. The common ends X and Y of the two CD4067s are respectively connected to the positive and negative ends of the analog signal bus. The entire slave circuit is powered by a single 5V power supply and consumes approximately 100mW.

3, system software design

The communication between the host PC and each slave communicates using the serial communication method 3 of the microcontroller. Mode 3 is a 9-bit variable baud rate data (except for the 1 start bit "0" and the 1 stop bit "1") asynchronous communication mode, which is the most used method in multi-machine communication. The key to the communication software design of PC and multi AT89C2051 one-chip computer lies in correct programming of the one-chip computer's serial control register SCON and the flexible use of the PC serial port interface.

When the AT89C2051 operates in Mode 3, a total of 11 bits of information are transmitted: 1 start bit (D0 = 0), 8 data bits (D1 ~ D8), 1 bit programmable bit (D9) and 1 stop bit (D10). The additional 9th ​​bit D9 is used as the identification flag for "address frame" and "data frame". This bit is generated on the transmit side by the TB8 bit in the serial control register and is automatically transmitted on the receive side to the RB8 bit in SCON. If D9=TB8=1, this frame information is an address, otherwise it is data. There is a multi-machine communication control bit SM2 in the serial control register SCON, which only receives the address frame when SM2=1, and can receive both the address frame and the data frame when SM2=0.

When the host PC communicates with a slave, the master first sends the command FFH to set the SM2 of each slave to 1 and then sends the slave's address m (00H to FFH). Note that the additional bit of the address frame is D9=1. At this time, all slaves perform serial interrupt response processing (entry address: 0023H). Each slave interrupt response processing is: comparing the received address number m with its own number, if not equal, ignore it; if equal, set SM2=0, and wait to continue receiving the channel number to be strobe n (0H ~ FH), then send n to P3 mouth. Finally, the host sends the channel number n. Since n is used as the data frame, D9=TB8=0 is set at this time. Since only the slave of the number m is equal to 0, the nth channel of the m slave is strobed. Only one channel of a slave can be strobed at any time.

To program the serial port of the host PC not only to select the same baud rate, but also to set the communication line controller LCR ingeniously. In order to match the mode 3 of the SCM, the setting of the LCR is: 8 digits long, Allow parity, 1 stop bit. Note that the parity bit D9 of the signal cannot be set to a fixed 0 or 1. Therefore, it is necessary to flexibly select Odd or Even parity to set D9 to 0 or 1. When sending an address frame, D9 needs to be 1, so if this When the number of "1"s in the binary code of the address is odd, the even parity is selected. If the number is even, the odd parity is selected. The opposite is true when sending data frames.

52 Modular Jack

52 Jack,Professional Plastic 6p6c RJ45 ModularJack manufacturer is located in China, including Top Entry Rj45,6p6c Modular Connectors,RJ45 Connector Diagram, etc.

The RJ-45 interface can be used to connect the RJ-45 connector. It is suitable for the network constructed by twisted pair. This port is the most common port, which is generally provided by Ethernet hub. The number of hubs we usually talk about is the number of RJ-45 ports. The RJ-45 port of the hub can be directly connected to terminal devices such as computers and network printers, and can also be connected with other hub equipment and routers such as switches and hubs.

Plastic 6p6c RJ45 ModularJack,Top Entry Rj45,6p6c Modular Connectors,RJ45 Connector Diagram

ShenZhen Antenk Electronics Co,Ltd , https://www.pcbsocket.com

This entry was posted in on