Please read this article before reading this article https://www.cnblogs.com/yangfengwu/p/7681702.html
First of all, it is clear that PLC is made with single-chip microcomputer. Later I will show you how to implement PLC functions with my own development board.
My PLC of choice is Mitsubishi
PLC model: FX1S-10MR-D 24V power supply, PLC is very small.
You don't need to buy a downloader, I have prepared the line for everyone, and you can download it directly with my development board
The interface of the download program of this PLC is 422 interface About various level transmission signals https://www.cnblogs.com/yangfengwu/p/5838059.html
The four that we use are connected to my board
PLC pins Development board pins
RxD+ ---- A+
RxD- ---- A-
TxD+ ---- B+
TxD- ---- B-
Then I measured this line
TxD+ ---- blue
TxD- ---- 黄
RxD+ ---- brown
RxD- ---- black
and so
Blue---- B+
Yellow---- B-
Brown---- A+
Black---- A-
Use this development board for demonstration https://www.cnblogs.com/yangfengwu/category/1508003.html
Note: A+ A- of the development board supports both sending and receiving data (485), B+ B- can only receive data
Because the PLC's RxD+ RxD- only receives data, only the sending function of the A+ A- pin is used
PLC's TxD+ TxD- only sends data, so the B+ B- pin is used to receive data
Power on the PLC
The recommended power supply for the PLC I use is 20V-26V, the relay is 12V, and the switch step-down is used. Generally, the voltage drop of the switch step-down chip is about 1V, so if it is stable, 14V power supply should be fine.
In fact, the 12V power supply does not matter. At most, the switch that powers the relay does not work, and it directly generates a voltage drop. Therefore, if the 12V power supply is supplied, the relay is about 11V, which can actually drive the relay.
I use 24V power supply, because I just have a 24V on hand, in fact, 12V can also be used
Don't worry about reverse connection,,,The circuit made inside is
Power on the development board (USB cable connected to the computer) Adjust the jumper cap to allow the computer serial port to communicate with 422
Note: In the future, no matter which development board you own, the connection between the PLC and the development board is fixed, and then the corresponding jumper cap is short-circuited to allow the computer serial port to communicate with 422
Install PLC software
Link: https://pan.baidu.com/s/1Cz6Xtm521mS1xPr5Yv8PgA
Extraction code: 1sud
Installation tutorial https://jingyan.baidu.com/article/e2284b2b6d23fbe2e6118db8.html
Open the software
Take a look at the serial port. Anyone who learns a single-chip computer should know the specific meaning, it's just computer serial communication.
Double click
Build a project, run a program, pay attention, because it is the first section, so just open mine directly, the first section is mainly to understand
This program is to control one of the relays 1S to pull in, 1S to disconnect Y0
You can also choose all of them. It is best to choose all of them. Not only download the program, but also save the comments to the microcontroller (PLC). In this case, when the program is read, it is a complete program.
After downloading, after the PLC is running, you will hear the sound of the relay 1S closing and 1S disconnecting.
Ok, now let's play a more thorough,,, make this board of mine into a PLC, the following code is the code for STM32 to implement PLC
Note: I just want to let others understand PLC better and have no other purpose. If the following tutorial involves the interests of others, please let me know and I will make changes. Thanks!
Let the computer serial port communicate with the MCU serial port 1
BOOT0 is connected to high level, and then reset the microcontroller
Remove the short circuit of Boot, and then reset the MCU
Let's rebuild a project
Let's control this pin
The PC11 of my development board happens to be connected to a relay
ldi m0
out y6
I will not demonstrate it anymore. My program to implement PLC with STM32 seems to have a BUG...
I'm just telling everyone the essence. The essence... please don't do bad things! Be a good boy who is safe and self-sacrificing.