Explanation of the Micro Programmable Controller Realized by AT89C51

Programmable controller is also called PLC. In the automation industry, programmable controller occupies an important position. For programmable controllers, the editor has introduced its theoretical knowledge in previous articles. In order to enhance everyone’s understanding of programmable controllers, this article will explain the micro programmable controller based on AT89C51. If you are interested in programmable controllers, you might as well continue reading.

A PLC composed of a single-chip microcomputer is actually a single-chip measurement and control system. Using such a program-controlled computer system to execute the relay control ladder program, because the relay control ladder diagram is parallel between the controlled electrical appliances, and in the computer program control, the controlled electrical appliances are in time It is a serial relationship, and the two are obviously not in harmony. If you simply collect the input terminal status in real time from each program line of the ladder diagram, and then output it in real time after processing, it will not achieve the purpose of control. For this reason, it is necessary to collect all input terminal states at one time and store them in the input buffer. Then, according to the logic relationship of the ladder diagram program line, read the corresponding input terminal state from the input buffer, and store the result to be output in the output buffer after processing. Finally, after all the ladder diagram program lines are executed, the value of the output buffer is output to the corresponding output terminal at one time, thereby completing a program execution cycle. In this reciprocation, the next round of acquisition of input terminal status is automatically carried out…. This working mode is called scanning mode, and it harmonizes the two relationships between serial program work and parallel work of electrical appliances. In addition, the time for the single-chip microcomputer to execute an instruction is μs, and the time to execute a scan cycle is several ms or even tens of ms. Compared with the action time of electrical appliances, the scanning period is short. It can be considered that the state of the input terminal is unchanged during a scanning period, and the collection and processing of its state changes are also real-time, thus satisfying real-time control. Require.

Explanation of the Micro Programmable Controller Realized by AT89C51

A total of 8 pins P1.7~1.0 are used for output control: when P1.i is “0”, the corresponding PNP tube is turned on, the relay Ji coil is energized, and its contact Y5i is turned on, which can drive 220V/3A loads .

In order to communicate with the PC, the system has expanded the RS-232C interface circuit. The RXD and TXD signals of the 51 single-chip microcomputer are connected to the 9-pin socket after RS-232C level conversion. This allows serial communication with a PC. On the one hand, in the programming state, it can receive the OBJ instruction code compiled by the ladder diagram assembler on the PC and store it in the program memory; on the other hand, in the running state, the I/O port status and processing results can be real-time Send to the host computer.

The program memory selects the X25045 chip with SPI interface. This is an E2PROM with programmable watchdog and power monitoring functions. It has 512 bytes and can be erased and written 100,000 times per byte. The data can be stored for 100 years. A 200ms high-level reset pulse is automatically provided upon power-up; there are three programmable watchdog periods; when the power supply is under-voltage, when VCC drops to the turning point, a reset pulse is automatically provided. E2PROM uses a three-wire bus serial peripheral interface SPI, which not only saves I/O ports and circuit board space, but also reduces system costs. Therefore, the chip is a combination chip with an excellent price/performance ratio.

The software design is divided into two parts: PC ladder diagram assembler compilation software and 51 single-chip microcomputer software. The former is written in IBM-PC assembly language, which we call PLC compiler software. In this machine, we have designed a set of TD-type PLC ladder diagram assembly language instruction system, including LD/LDI, AN/ANI, OR/ORI, TM/TMI, CN/CNI, MA/MAI, OUT, JP/JE 16 basic commands such as END and X00~07, X10~14, Y00~07, CN0~1, TM00~07, MA00~07, 10~17 and other devices. Use them to describe the relay ladder diagram, that is, design the ladder diagram assembler. Use the full-screen editing software to input it into the PC, that is, the source program file is established. Then use PLC compiling software to compile it into a PLC target program file (OBJ file), and send it to the single-chip microcomputer through the serial communication port, and the single-chip microcomputer writes it into the E2PROM.

51 single chip microcomputer software consists of programming software and operating software. The programming software mainly has two modules: serial communication and writing E2PROM. At this time, the manual switch on the panel must be set to P2.7 = “0”, and the microcontroller is in the programming state. When P2.7 = “1”, the microcontroller is in the running state. The running state of the program mainly includes:

(1) Input terminal acquisition module

The module collects the status of P0 and P1 twice, and the results are all valid at the same time, that is, they are stored in the input buffer, otherwise they are collected again. The software filtering method improves the anti-interference ability.

(2) Instruction analysis module

The module starts from address 000H, reads the byte content in E2PROM in turn, reads the opcode first, analyzes it, and then turns to the corresponding processing program; then reads the operand for the processing program to operate, thereby completing a ladder diagram assembly instruction Implementation. Then read the opcode of the next instruction…. When the OUT instruction is encountered, the data to be output is stored in the corresponding output buffer.

(3) Output module

When the CPU reads the binary code of the END instruction from the E2PROM, it means that a scan cycle is over, that is, the content of the output buffer is output to the P1 port at one time, thereby completing the refresh of the output terminal.

The application of this PLC can be illustrated by the example of water tower water level control.

Figure 2 (a) is the hardware wiring diagram, SB1/SB2 is the start/stop button; SAC is the pool level switch: it is connected when the water is immersed, and it is disconnected when there is no water; SAH and SAL are the high and low level switches of the water tower respectively ; M is the water pump motor.

Figure 2 (b) is the relay ladder diagram, and Figure 2 (c) is the relay assembly program, that is, the TD-type PLC source program. Among them, y50 is the PLC output terminal. We use its software contact y50 as a sign of rising or falling water level: y50=”0″, which means that the motor has stopped and the water level has fallen. At this time, although the SAL is connected, the motor does not operate; y50=”1″, it means that the motor is pumping water and the water level is rising. At this time, SAL is connected and the motor is energized to continue pumping until the high water level.

The system has fulfilled the expected functional goals. The micro programmable controller based on AT89C51 has its own advantages and is widely used in production and life.

The Links:   1MBI600PX-120 G121STN010

Author: Yoyokuo