Skip to content

GeraldWodni/ladder-14500

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assembler & Ladder Logic made in Forth

This projcet is based on Nicola Cimmino's wonderful PLC-14500 project. It uses a MC14500 1-bit-cpu, which is purpose-made for PLC-like applications e.g. systems that run ladder-logic.

Assembler

You can find the assembler in assi.4th, see also the asm-examples directory for some simple example. For people who want to see source code immediatly, here it is:

include ./assi.4th

: START IN0 ;
: STOP IN1 ;
: OVERHEAT IN3 ;

: MOTOR OUT0 ;

(start)
ORC RR
IEN RR
OEN RR

LD START
OR SPR0
ANDC TMR
STO SPR0

LD SPR0
ANDC STOP
STOC SPR0

LD SPR0
STO MOTOR

LD OVERHEAT
STO TMR

JMP
(end)

bye

(start) resets the internal program counter and the program memory.
(end) writes the program to out.hex
To upload the file to the PLC-14500, i just pipe it to the serial port: cat out.hex > /dev/ttyUSB0
You can set the speed of the serial port by using stty: stty 9600 /dev/ttyUSB0.

Putting it all together you would run the assembler non-interactively by using it like so:

gforth <filename.4th> && cat out.hex > /dev/ttyUSB0

Hint: this is a Standard Program, feel free to use your favourite Forth system like vfxforth, swiftforth, of whatever floats you bits.

Disassembler

If you want to inspect compiled code, use dasm.4th:

s" out.hex" dasm-file

Ladder

The Forth-ASCII-ladder-logic has its own repository, and is adopted for this repo. The ladder logic directly uses the above assembler to generate code.

Here is a latching motor example:

(start)
||
||- -| START |-        -+
||- -| MOTOR-MERKER |- -+- -|/ STOP |- -( MOTOR-MERKER )- -||
||
||- -| MOTOR-MERKER |- -( MOTOR )- -||
||
(end)

About

Ladder-logic compiler in Forth for PLC-MC14500 1-bit-cpu

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages