Abstract: PLC systems are widely used industrial automation devices, but their data or parameters cannot be displayed due to the lack of a matching digital display instrument. This paper presents a scheme for implementing a digital display instrument that connects to the PLC system using only two I/O lines, detailing the hardware composition, timing design, software implementation, and application methods based on the STC89C51 microcontroller. This digital display instrument can be directly connected to various PLCs with transistor output or voltage output, realizing the data or parameter display function of the PLC system. Keywords: STC89C51; PLC; Human Machine Interface; Digital Display Meter; Two Line Connection Abstract: PLC system is an automatic equipment widely used in industry control, but it can't display its data or parameters as it has no corresponding display unit. This paper introduces a scheme of display meter connecting PLC system with only two output points. It illustrates hardware composing based on STC89C51, timing diagram design, software realization and applicable method. This digital display meter may directly connect with a transistor-output or voltage-output PLC system and display its data or parameters. Keywords: STC89C51; PLC; Human Machine Interface; Digital Display Meter; Two Line Connection 0 Introduction Programmable Logic Controller (PLC) has the characteristics of simple programming, high reliability, strong versatility and easy use, and is widely used in various production processes in industrial control[1]. Current PLC systems mostly use indicator lights to display the status signals of the production process or equipment, or rely on dedicated human-machine interfaces (HMIs) or industrial PCs to display process variables or set system parameters. HMIs and IPCs not only increase the cost of PLC systems but also cannot adapt to high-temperature, high-humidity, and dusty working environments. LED-based digital display instruments have advantages such as strong environmental adaptability, intuitive display, and high visibility, and can meet the special display needs of certain industrial sites. However, if the PLC system's I/O is used to directly drive the digital tube for display, it requires a large amount of PLC system I/O resources. This paper uses microcontroller and program control technology, through specific transmission timing, to achieve parameter display using only two I/O points of the PLC system. 1 Hardware Design The hardware composition of the two-wire connected digital display instrument of the PLC system implemented with STC89C51 as the core is shown in Figure 1. The entire hardware system mainly consists of an STC89C51 microcontroller, input interface, program download interface, digital tube display driver circuit, key input (optional), and alarm output (optional). STC89C51 and standard 80C51 maintain hardware structure and instruction system compatibility, improve clock rate, and expand in-system programming (ISP), in-application programming (IAP), power undervoltage detection and reset, watchdog reset and other functions. Its I/O ports have been specially designed to make it highly reliable in industrial control environment[2]. [align=center] Figure 1 Hardware composition of PLC system two-wire connection type digital display instrument[/align] 1.1 PLC system input interface The PLC system transmits display data to the digital display instrument in a certain timing sequence through two output points. PLC systems generally have a variety of forms to choose from, such as relay output, thyristor output, transistor output and 24V DC voltage output. Generally, its transistor output or 24V output form is used to connect to the digital display instrument through the corresponding conversion circuit. In order to adapt to the two output forms, an optocoupler is used to uniformly convert the output signal of the PLC system into a TTL level signal. If the output form of the PLC system is 24VDC, such as Siemens S7 series PLC, the connection between the PLC output and the input side of the optocoupler is shown in Figure 2. If the output of the PLC system is a transistor open collector or open drain output, such as the Mitsubishi FX series PLC, the connection between the PLC output and the input side of the optocoupler is shown in Figure 3. Regardless of the connection method, the signal logic entering the STC89C51 microcontroller after conversion is consistent with the output logic of the PLC system. Using an optocoupler to realize signal conversion is beneficial to improve the anti-interference capability of the system, because even if the interference signal has a high voltage amplitude, its energy is relatively small, and the weak current formed is generally insufficient to make the optocoupler conduct [3]. The two converted signals are used as data lines and clock lines, respectively, and connected to the two external interrupt input pins of the microcontroller, which facilitates the transmission of display data using the interrupt method. [align=center] Figure 2 Voltage output type PLC interface Figure 3 Transistor output type PLC interface[/align] 1.2 Program download interface With the help of the ISP programming function, the program code can be downloaded from the computer to the Flash inside the microcontroller through the RS-232C interface. The program download interface is generally designed as a standard RS-232 interface, which can be implemented using a MAX232 conversion chip. 1.3 Digital Tube Driver Circuit To ensure the brightness of the digital tube display, two 74HC245 chips are used to drive the digital tube. One 74HC245 drives the segment codes of the 4-digit common cathode digital tube. Its input is connected to the P0 port of the microcontroller, and its output is connected to the 8 segment code pins of the 4-digit digital tube after current limiting by a current-limiting resistor. The other 74HC245 drives the digit codes of the 4-digit digital tube. Its input is connected to P1.0 to P1.3 of the microcontroller, and its output is connected to the common terminal of the 4-digit digital tube. 2. Transmission Timing When transmitting data between a digital display instrument and a PLC, two output points of the PLC are required, used as the data line and clock line respectively. Since the transmission of display data is serial, a corresponding transmission timing sequence must be designed. When constructing the transmission timing sequence for both parties, the working principle of the PLC system, its output characteristics and differences, and the reliability of the transmission process must be fully considered. The transmission timing sequence designed after comprehensively considering these factors is shown in Figure 4. Transmitting one set of display data requires a total of 21 clock cycles, of which 3 clock cycles are used for synchronization signals, 16 clock cycles are used for transmitting the 4-bit BCD code of the display data or specific prompt characters, and 2 clock cycles are used for transmitting 2 bits of information indicating the decimal point display position. The low-order bits of the display data and the decimal point position information are first, and the high-order bits are last. For example, Figure 4 shows that the transmitted display data is 8951, and the decimal point position information is 10, indicating that the decimal point is after the tens place, so the final display data is 895.1. [align=center] Figure 4 Transmission timing between digital display instrument and PLC system[/align] Since the PLC system refreshes the input signal, executes the user program and outputs the running results repeatedly based on the scanning principle [4], it is difficult to make the output signal of the PLC system jump within one scan cycle. Therefore, one clock cycle in Figure 4 requires two scan cycles of the PLC system. The addition of 3 synchronization pulses in each transmission process is to improve the reliability of the transmission process and ensure that the PLC system and its transmission line can correctly transmit the display data within one transmission cycle after the fault is recovered, regardless of what kind of fault occurs. 3. Software Design The program for the digital display instrument consists of four parts: initialization, external interrupt 0 service routine, external interrupt 1 service routine, and timer T0 interrupt service routine. T0 interrupts once every 5ms. In its interrupt service routine, the dynamic display of the 4-digit LED display is completed based on the received display data and its decimal point position information. The external interrupt 0 service routine is used to detect the synchronization signal, and the external interrupt 1 service routine is used to receive the BCD encoding of the 16-bit display data and 2 bits of information indicating the decimal point display position. 3.1 External Interrupt 0 Service Routine External interrupt 0 is triggered by the falling edge of the data signal line. In its interrupt service routine, if a low level is detected on the clock line, it is considered a synchronization signal. After three synchronization pulses are detected, it indicates that a correct synchronization signal has been received. At this time, external interrupt 0 is disabled, and external interrupt 1 is enabled, using the external interrupt 1 service routine to receive data. If a synchronization pulse was detected in the previous one or two interrupt service routines but is not detected this time, it is considered an invalid synchronization signal. The main code of the external interrupt 0 service routine is as follows: void Int0_Srvice(void) interrupt 0 { p33=1; if (p33==0) SysClock++; //Valid, increment the synchronization pulse by 1 else SysClock=0; //Invalid, clear the synchronization pulse if (SysClock==3) { //Detect 3 synchronization pulses RecEnable=1; //Set the enable receive flag EX0=0; //Disable external interrupt 0 EX1=1; //Enable external interrupt 1 }} 3.2 External Interrupt 1 Service Routine External interrupt 1 is triggered by the falling edge of the clock signal line. In its interrupt service routine, if the enable receive flag is found to be established, it receives the BCD code of 16-bit display data and 2-digit decimal point position information, converts them into 18-bit parallel data, and stores them in the DispData variable for display by the T0 interrupt service routine. Since both the displayed data and the decimal point position information are displayed with the least significant digit first and the most significant digit last, a right shift operation is used in the program to convert serial data to parallel data. When the decimal point position information is 0 to 3, it indicates that the decimal point is located after the thousands, hundreds, tens, and ones places on the digital display, respectively. If the decimal point is after the ones place, it is not displayed. After receiving 18 bits of information, external interrupt 1 is disabled, and external interrupt 0 is re-enabled to begin the next cycle of data transmission. The main code of the external interrupt 1 service routine is as follows: void Int1_Srvice(void) interrupt 2 { if (RecEnable==1) // Enable reception { p32=1; // Detect data line level if (p32==1) RecData=RecData|0x40000; RecData=RecData>>1; // Implement serial/parallel conversion DataClock++; if (DataClock==19) // 18 bits of data have been received { // Display data stored in DispData DispData=RecData;RecData=0; SysClock=0;DataClock=0; RecDone=1;RecEnable=0; EX0=1; // Enable external interrupt 0 EX1=0; // Disable external interrupt 1 } } 4 Application Example The PLC system can connect to n digital display instruments using its (n+1) output points, with one point used as a common clock line and n points used as data lines for the n digital display instruments. When displaying data or parameters from the PLC system using digital display instruments, a driver program that meets timing requirements must be written for the PLC system. 4.1 PLC Driver Design This section uses the Mitsubishi FX2N PLC system as an example to introduce the method of writing a PLC system driver. Assuming Y0 is used as the data line and Y1 as the clock line, the ladder diagram of the PLC driver program is shown in Figure 5. The program uses unit D0 to store the display data, with a value range of 0 to 9999, and unit D1 to store the decimal point position information, with a value range of 0 to 3. The resources used include counters C0 to C1 and intermediate relays M100 to M131, which can be adjusted according to the user program. [align=center]Figure 5 FX2N PLC Display Driver[/align] 4.2 Connection of Multiple Digital Display Instruments to the PLC System The connection of multiple digital display instruments to the PLC system is shown in Figure 6. In the figure, one FX2N PLC connects to eight digital display instruments. PLC Y10 is used as a common clock line, and Y0 to Y7 are used as data lines for the eight digital display instruments respectively. The PLC system driver is similar to that in Figure 5. Since the clock lines of multiple instruments are common and the data lines are output in parallel, the data refresh time of multiple digital display instruments is independent of the number of connections, ensuring the real-time display of the PLC system. 5 Conclusion This digital display instrument does not need to know any PLC system protocol. It only needs to use n+1 output points of the PLC system to display its data or parameters on n digital display instruments. It occupies fewer PLC resources, which can both expand the peripheral display devices of the PLC system and indirectly solve practical engineering problems such as the inability of HMI to adapt to harsh working environments. The instrument has been applied to the display of 12 remote manual operation signals in waste power generation. The application results show that it has extremely high reliability and good maintainability. The innovation of the author of this article is that the digital display instrument solves the problem of PLC system directly driving digital tube occupying too many resources, and indirectly solves the problem that a type of digital display instrument based on PLC system communication port needs to know the communication protocol. References: [1] Tang Mingjun, Tang Huiqiang, Huang Jinyan. Hardware design of programmable controller based on ARM[J]. Instrument Technology and Sensors, 2006(5):40-41 [2] Wu Weiqi. STC89 series high performance single microcontroller and its application[J]. Microcomputer Information, 2004(7):92-93 [3] Li Zhengjun. Computer Control System[M]. Beijing: Machinery Industry Press, 2006:94-99 [4] Yu Hanqi, Sheng Danghong, Deng Donghua. Electrical Control and Programmable Controller[M]. Nanjing: Southeast University Press, 2003:145-152