IEC 61131-3 uses symbolic variables declared in sections at the top of each program. Direct addresses with a percent sign exist for located variables, but most CODESYS projects map I/O in the device tree and use names. This sheet lists the address forms, data types, literals and block pins you need to read IEC code.
| Item | Syntax | Meaning |
|---|---|---|
| Input bit | %IX0.0 | Byte 0, bit 0 of the input area. |
| Output bit | %QX0.0 | Byte 0, bit 0 of the output area. |
| Memory bit | %MX0.0 | Byte 0, bit 0 of the memory area. |
| Byte, word, double word | %IB0 %IW0 %ID0 | 8, 16 and 32 bits starting at byte 0 of the input area. Q and M work the same. |
| Located variable | Start AT %IX0.0 : BOOL; | Gives a name to a direct address. |
| Item | Syntax | Meaning |
|---|---|---|
| Bit and bit strings | BOOL BYTE WORD DWORD LWORD | 1, 8, 16, 32 and 64 bits. |
| Signed integers | SINT INT DINT LINT | 8, 16, 32 and 64 bits. |
| Unsigned integers | USINT UINT UDINT ULINT | 8, 16, 32 and 64 bits. |
| Floating point | REAL LREAL | 32 and 64 bits. |
| Time | TIME | A duration. |
| Item | Syntax | Meaning |
|---|---|---|
| Time | T#3s T#500ms T#1h30m | Durations. |
| Based integers | 16#FF 2#1010 8#17 | Hexadecimal, binary and octal. |
| Booleans | TRUE FALSE | The two BOOL values. |
| Item | Syntax | Meaning |
|---|---|---|
| Sections | VAR VAR_INPUT VAR_OUTPUT VAR_IN_OUT VAR_GLOBAL | Where a variable lives and how it is passed. |
| Modifiers | VAR RETAIN VAR CONSTANT | Keep across a warm restart, and fixed values. |
| Unit types | PROGRAM FUNCTION FUNCTION_BLOCK | A task-run program, a memory-less function and a block with instances. |
| Item | Syntax | Meaning |
|---|---|---|
| Timers | TON TOF TP | Inputs IN and PT; outputs Q and ET. |
| Counters | CTU CTD CTUD | Count inputs CU and CD, reset or load, preset PV; outputs Q (QU and QD for CTUD) and count CV. |
| Edge blocks | R_TRIG F_TRIG | Input CLK; output Q is true for one call on a rising or falling edge. |
| Calling a block | T_PUMP(IN := PUMP_REQ, PT := T#3s); | Named inputs, then read T_PUMP.Q afterwards. |
| Item | Syntax | Meaning |
|---|---|---|
| Ladder text | | (START OR MOTOR) AND NOT STOP | := MOTOR ; | A rung: the condition between bars, := then the coil. |
| Reading a block output | | T_PUMP.Q | := PUMP_RUN ; | Block outputs are read in a ladder-text rung, not on the right of an assignment. |
| Functions as calls | IS_HIGH := GT(LEVEL, 70); | Comparison and arithmetic are written as function calls here, not infix operators. |
Always confirm addresses and ranges against the manual for your exact controller and software version. Want to see these addresses used in logic? Read the CODESYS and IEC 61131-3 instruction reference.
The percent sign marks a direct address. I is the input area, X means a single bit, and 0.0 is byte 0, bit 0. %QX is the output area and %MX the memory area, and B, W and D select a byte, word or double word.
Most projects map I/O in the device tree and use symbolic names, because it is easier to maintain. Direct addresses with AT still appear in older code and examples, so you need to be able to read them.
Use a TIME literal such as T#3s for three seconds, T#500ms for half a second or T#1h30m for an hour and a half.
Training material. Follow your site procedures, local electrical code and the manufacturer's instructions. Lockout/tagout and a qualified person are required for real equipment.