PLC Simulator
CODESYS and IEC 61131-3 cheat sheet

CODESYS and IEC 61131-3 addressing cheat sheet

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.

Direct addresses

Direct addresses
ItemSyntaxMeaning
Input bit%IX0.0Byte 0, bit 0 of the input area.
Output bit%QX0.0Byte 0, bit 0 of the output area.
Memory bit%MX0.0Byte 0, bit 0 of the memory area.
Byte, word, double word%IB0 %IW0 %ID08, 16 and 32 bits starting at byte 0 of the input area. Q and M work the same.
Located variableStart AT %IX0.0 : BOOL;Gives a name to a direct address.

Elementary data types

Elementary data types
ItemSyntaxMeaning
Bit and bit stringsBOOL BYTE WORD DWORD LWORD1, 8, 16, 32 and 64 bits.
Signed integersSINT INT DINT LINT8, 16, 32 and 64 bits.
Unsigned integersUSINT UINT UDINT ULINT8, 16, 32 and 64 bits.
Floating pointREAL LREAL32 and 64 bits.
TimeTIMEA duration.

Literals

Literals
ItemSyntaxMeaning
TimeT#3s T#500ms T#1h30mDurations.
Based integers16#FF 2#1010 8#17Hexadecimal, binary and octal.
BooleansTRUE FALSEThe two BOOL values.

Variable sections and unit types

Variable sections and unit types
ItemSyntaxMeaning
SectionsVAR VAR_INPUT VAR_OUTPUT VAR_IN_OUT VAR_GLOBALWhere a variable lives and how it is passed.
ModifiersVAR RETAIN VAR CONSTANTKeep across a warm restart, and fixed values.
Unit typesPROGRAM FUNCTION FUNCTION_BLOCKA task-run program, a memory-less function and a block with instances.

Standard block pins

Standard block pins
ItemSyntaxMeaning
TimersTON TOF TPInputs IN and PT; outputs Q and ET.
CountersCTU CTD CTUDCount inputs CU and CD, reset or load, preset PV; outputs Q (QU and QD for CTUD) and count CV.
Edge blocksR_TRIG F_TRIGInput CLK; output Q is true for one call on a rising or falling edge.
Calling a blockT_PUMP(IN := PUMP_REQ, PT := T#3s);Named inputs, then read T_PUMP.Q afterwards.

In this browser editor

In this browser editor
ItemSyntaxMeaning
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 callsIS_HIGH := GT(LEVEL, 70);Comparison and arithmetic are written as function calls here, not infix operators.

What this sheet leaves out

  • The reset input name on counters, which differs between the standard text and library versions.
  • Structured data types, arrays and pointers.
  • Device tree I/O mapping, which replaces direct addresses in most projects.

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.

Frequently asked questions

What does %IX0.0 mean?

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.

Should I use direct addresses in a CODESYS project?

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.

How do I write a time value?

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.