📄 tiny_plc.txt
字号:
Digital outputs, see TINYPLC.H for output logic values.
ADC0 .. ADC7 -- PF0 (ADC0) .. PF7 (ADC7), analog inputs.
JTAG debugging (optional) -- when enabled in TINYPLC.H, JTAG pins
(PF4 .. PF7) are allocated for debugging, which reduces the
number of analog ports to 4 (ADC0 .. ADC3 on PF0 .. PF3).
FLASH -- 5554 words (~9% of available 64K words (~4% of 128K on 2561))
RAM -- 2590 bytes (~32% of available 8192 bytes)
EEPROM -- 1030 bytes (~25% of available 4096 bytes)
TMR0 -- used for TinyPLC timer / interrupt.
ADC -- used for analog inputs
USART0 -- serial communications
Note that all I/O pins are used. If additional hardware features are
desired (2nd USART, hardware PWM's, etc), the pins used must be taken
from the pool of DIG_IN and DIG_OUT pins.
When the processor board is powered up, if the PLC program in EEPROM is
valid it is copied from EEPROM to RAM, the program valid flag is set, and
the "soft run" flag is set. Then if the hardware run switch is set to RUN,
the PLC program is executed.
If a command from PLC.EXE is received, TinyPLC takes the appropriate action.
For example, a STOP action in PLC tells TinyPLC to clear the "soft run" flag,
while the RUN action in PLC tells TinyPLC to set the "soft run" flag. When
PLC.EXE downloads a program, if a valid program is received (you always make
allowances for transmission errors) it is copied into EEPROM.
---------------------------------------------------------------------------
Section III: Technical notes and suggested improvements
The TinyPLC package was designed, written, and tested in a month. It
shows.
While the basics are in place and work, the original design, even if
it was bad, was made to work. There are a number of "hooks" that have
never been finished.
Hopefully, either I or someone else will take the time to improve TinyPLC.
TinyPLC datatypes. Modify PLCSHARE.H to change the number of registers
allocated to each datatype:
INPUTS: There are 32 inputs, X0 .. X31.
OUTPUTS: There are 32 outputs, Y0 .. Y31.
ANALOGS: There are 32 analog inputs, A0 .. A31.
VARIABLES: There are 32 variables, V0 .. V31. Each variable can hold a
32-bit number. V31 is special, and contains the status flags
from arithmetic and logical
operations.
V31 & 1 = Carry status
V31 & 2 = Overflow status
V31 & 4 = Zero status
V31 & 8 = Negative status
V31 & 16 = Stack overflow/underflow error
V31 & 32 = Divide by 0 error
TIMERS: There are 16 timers, T0 .. T15. Each timer is 32-bits (0 ..
4,294,967,295) with 1ms resolution.
Note: each timer uses 2 32-bit storage locations.
COUNTERS: There are 32 counters, C0 .. C31. Each counter is 32-bits
(0 .. 4,294,967,295).
ONESHOTS: There are 32 oneshot registers, R0 .. R31
NOTE: when a ladder program is initalized, the previous state
of the inputs to oneshots is assumed to be FALSE. As a
result, a oneshot can be used at the start of a rung to
execute initalization logic.
TinyPLC opcodes:
Name Opcode byte(s) (HEX) Comments
============= ==================== =================================
NOP 0x00 NOP
BRK 0x01 STOP execution if debug, else NOP
(not currently implemented)
SETLINETRUE 0x02 Set "Line Truth" to TRUE
(start of rung)
PUSHLINETRUE 0x03 Save "Line Truth" value on initstack
ORBRANCH 0x04 Save current "Line Truth" value on
resultstack, pop "Line Truth"
value from initstack
ORPOPLINETRUE 0x05 Pop value from resulstack and OR to
"Line Truth" value
INP 0x06 <reg> If <reg> is not 0, set rung to TRUE
else FALSE
<reg> may refer to any data type
NINP 0x07 <reg> If <reg> is 0, set rung to TRUE else
FALSE
<reg> may refer to any data type
OUT 0x08 <reg> Set <reg> to value of rung
NOUT 0x09 <reg> Set <reg> to value of !rung
<reg> may refer to an OUTPUT or
VARIABLE
LOUT 0x0a <reg> If rung is TRUE set output
<reg> may refer to an OUTPUT or
VARIABLE
UOUT 0x0b <reg> If rung is TRUE clear output
<reg> may refer to an OUTPUT or
VARIABLE
ADD 0x0c <r1> <r2> <dest> If rung is TRUE do
R1 + R2 --> Dest and set flags
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
ADDB 0x0d <r1> <BVAL> <dest> If rung is TRUE do
R1 + BVAL --> Dest and set flags
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
SUB 0x0e <r1> <r2> <dest> If rung is TRUE do
R1 - R2 --> Dest and set flags
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
SUBB 0x0f <r1> <BVAL> <dest> If rung is TRUE do
R1 - BVAL --> Dest and set flags
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
MUL 0x10 <r1> <r2> <dest> If rung is TRUE do
R1 * R2 --> Dest and set flags
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
MULB 0x11 <r1> <BVAL> <dest> If rung is TRUE do
R1 * BVAL --> Dest and set flags
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
DIV 0x12 <r1> <r2> <dest> If rung is TRUE
If R2 is 0
set error flag DIV
and set rung to FALSE
else
do R1 / R2 --> Dest
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
DIVB 0x13 <r1> <BVAL> <dest> If rung is TRUE
If R2 is 0
set error flag DIV
and set rung to FALSE
else
do R1 / BVAL --> Dest
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
MOD 0x14 <r1> <r2> <dest> If rung is TRUE
If R2 is 0
set error flag DIV
and set rung to FALSE
else
do R1 % R2 --> Dest
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
MODB 0x15 <r1> <BVAL> <dest> If rung is TRUE
If R2 is 0
set error flag DIV
and set rung to FALSE
else
do R1 % BVAL --> Dest
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
AND 0x16 <r1> <r2> <dest> If rung is TRUE do
R1 & R2 --> Dest and set flags
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
ANDB 0x17 <r1> <BVAL> <dest> If rung is TRUE do
R1 & BVAL --> Dest and set flags
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
OR 0x18 <r1> <r2> <dest> If rung is TRUE do
R1 | R2 --> Dest and set flags
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
ORB 0x19 <r1> <BVAL> <dest> If rung is TRUE do
R1 | BVAL --> Dest and set flags
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
XOR 0x1a <r1> <r2> <dest> If rung is TRUE do
R1 ^ R2 --> Dest and set flags
<r1> and <r2> may refer to any data
type. <dest> must be an OUTPUT or
VARIABLE.
XORB 0x1b <r1> <BVAL> <dest> If rung is TRUE do
R1 ^ BVAL --> Dest and set flags
<r1> may refer to any data type.
<dest> must be an OUTPUT or VARIABLE
NOT 0x1c <reg> If rung is TRUE do
~Reg --> Reg and set flags
<reg> must be an OUTPUT or VARIABLE
NEG 0x1d <reg> If rung is TRUE do
-Reg --> Reg and set flags
<reg> must be an OUTPUT or VARIABLE
EQU 0x1e <r1> <r2> If R1 == R2 set rung to TRUE else FALSE
<r1> and <r2> may refer to any data
type
EQUB 0x1f <r1> <BVAL> If R1 == BVAL set rung to TRUE else FALSE
<r1> may refer to any data type
NEQ 0x20 <r1> <r2> If R1 != R2 set rung to TRUE else FALSE
<r1> and <r2> may refer to any data
type
NEQB 0x21 <r1> <BVAL> If R1 != BVAL set rung to TRUE else FALSE
<r1> may refer to any data type
GRT 0x22 <r1> <r2> If R1 > R2 set rung to TRUE else FALSE
<r1> and <r2> may refer to any data
type
GRTB 0x23 <r1> <BVAL> If R1 > BVAL set rung to TRUE else FALSE
<r1> may refer to any data type
GEQ 0x24 <r1> <r2> If R1 >= R2 set rung to TRUE else FALSE
<r1> and <r2> may refer to any data
type
GEQB 0x25 <r1> <BVAL> If R1 >= BVAL set rung to TRUE else FALSE
<r1> may refer to any data type
LES 0x26 <r1> <r2> If R1 < R2 set rung to TRUE else FALSE
<r1> and <r2> may refer to any data
type
LESB 0x27 <r1> <BVAL> If R1 < BVAL set rung to TRUE else FALSE
<r1> may refer to any data type
LEQ 0x28 <r1> <r2> If R1 <= R2 set rung to TRUE else FALSE
<r1> and <r2> may refer to any data
type
LEQB 0x29 <r1> <BVAL> If R1 <= BVAL set rung to TRUE else FALSE
<r1> may refer to any data type
MOV 0x2a <dest> <r1> If rung is TRUE move R1 to Dest
<dest> and <r1> must both be VARIABLES
MOVD 0x2b <dest> <B0> <B1> <B2> <B3>
If rung is TRUE move DVAL to Dest
<dest> must be a VARIABLE
JMP 0x2c <B0> <B1> If rung is TRUE goto Label
OSR 0x2d <reg> If previous scan was FALSE and rung
is TRUE, output TRUE else FALSE
<reg> must be a ONESHOT
CTT 0x2e <reg> <B0> <B1> If previous scan was FALSE and rung
is TRUE, update counter and flags.
Outputs DONE to rung
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -