Programming instructions 6
6.1 Basic instructions
6.1.9 Logical operations
AND, OR, and XOR instructions
● AND: Logical AND for BYTE, WORD, and DWORD data types
● OR: Logical OR for BYTE, WORD, and DWORD data types
● XOR: Logical exclusive OR for BYTE, WORD, and DWORD data types
LAD FBD
Click below the box name and select a data type from the drop menu.
长沙工控帮教育科技有限公司整理
Programming instructions 6.1 Basic instructions
Parameter Data type Description
IN1, IN2 BYTE, WORD, DWORD Logical inputs
OUT BYTE, WORD, DWORD Logical output
The data type selection sets parameters IN1, IN2, and OUT to the same data type. The corresponding bit values of IN1 and IN2 are combined to produce a binary logic result, at parameter OUT. ENO is always TRUE following the execution of these instructions.
Invert instruction
You use the INV instruction to get the binary one's complement of the parameter IN. The one's complement is formed by inverting each bit value of the IN parameter (changing each 0 to 1 and each 1 to 0). ENO is always TRUE following the execution of this instruction.
LAD FBD
Click below the box name and select a data type from the drop-down menu.
Parameter Data type Description
IN SINT, INT, DINT, USINT, UINT, UDINT, BYTE,
WORD, DWORD Data element to invert
OUT SINT, INT, DINT, USINT, UINT, UDINT, BYTE,
WORD, DWORD Inverted output
Encode and decode instructions
● ENCO encodes a bit pattern to a binary number
● DECO decodes a binary number to a bit pattern
LAD FBD
Click below the box name and select a data type from the drop-down menu.
长沙工控帮教育科技有限公司整理
Programming instructions 6.1 Basic instructions
Parameter Data type Description
IN ENCO: BYTE, WORD, DWORD
DECO: UINT
ENCO: Bit pattern to encode DECO: Value to decode
OUT ENCO: INT
DECO: BYTE, WORD, DWORD
ENCO: Encoded value DECO: Decoded bit pattern
The ENCO instruction converts parameter IN to the binary number corresponding to the bit position of the least-significant set bit of parameter IN and returns the result to parameter OUT. If parameter IN is either 0000 0001 or 0000 0000, then a value of 0 is returned to OUT.
If the parameter IN value is 0000 0000, then ENO is set to FALSE.
The DECO instruction decodes a binary number from parameter IN, by setting the corresponding bit position in parameter OUT to a 1 (all other bits are set to 0). ENO is always TRUE following execution of the DECO instruction.
The DECO parameter OUT data type selection of a BYTE, WORD, or DWORD restricts the useful range of parameter IN. If the value of parameter IN exceeds the useful range, then a modulo operation is performed to extract the least significant bits shown below.
DECO parameter IN range:
● 3 bits (values 0-7) IN are used to set 1 bit position in a byte OUT
● 4-bits (values 0-15) IN are used to set 1 bit position in a word OUT
● 5 bits (values 0-31) IN are used to set 1 bit position in a double word OUT
DECO IN value DECO OUT value ( Decode single bit position) BYTE OUT (8 bits):
Min. IN 0 00000001
Max. IN 7 10000000
WORD OUT (16 bits):
Min. IN 0 0000000000000001
Max. IN 15 1000000000000000
DWORD OUT: (32 bits):
Min. IN 0 00000000000000000000000000000001 Max. IN 31 10000000000000000000000000000000
Condition codes for ENCO
ENO status Condition Result (OUT)
1 No error Valid bit number
0 IN is zero OUT is set to zero
长沙工控帮教育科技有限公司整理
Programming instructions 6.1 Basic instructions
Select (SEL) and Multiplex (MUX) instructions
● SEL assigns one of two input values to parameter OUT, depending on the parameter G value.
● MUX assigns one of many input values to parameter OUT, depending on the parameter K value. If the parameter K value exceeds the valid range, the parameter ELSE value is assigned to parameter OUT.
LAD FBD
Click below the box name and select a data type from the drop-down menu.
Parameters for SEL
Parameter Data type Description
G BOOL Selector switch:
• FALSE for IN0
• TRUE for IN1 IN0, IN1 SINT, INT, DINT, USINT, UINT, UDINT, REAL, BYTE,
WORD, DWORD, TIME, CHAR Inputs
OUT SINT, INT, DINT, USINT, UINT, UDINT, REAL, BYTE,
WORD, DWORD, TIME, CHAR Output
Parameters for MUX
Parameter Data type Description
K UINT Selector value:
• 0 for IN0
• 1 for IN1
• ...
IN0, IN1, .... SINT, INT, DINT, USINT, UINT, UDINT, REAL, BYTE,
WORD, DWORD, TIME, CHAR Inputs
长沙工控帮教育科技有限公司整理
Programming instructions 6.1 Basic instructions
Parameter Data type Description
ELSE SINT, INT, DINT, USINT, UINT, UDINT, REAL, BYTE,
WORD, DWORD, TIME, CHAR Input substitute value
(optional) OUT SINT, INT, DINT, USINT, UINT, UDINT, REAL, BYTE,
WORD, DWORD, TIME, CHAR Output
Input variables and the output variable must be of the same data type.
● The SEL instruction always selects between two IN values.
● The MUX instruction has two IN parameters when first placed in the program editor, but it can be expanded to add more IN parameters.
Use the following methods to add and remove input parameters for the MUX instruction:
● To add an input, right-click on an input stub for one of the existing IN parameters and select the "Insert input" command.
● To remove an input, right-click on an input stub for one of the existing IN parameters (when there are more than the original two inputs) and select the "Delete" command.
Condition codes
ENO is always TRUE following execution of the SEL instruction.
ENO status (MUX) MUX condition MUX result OUT
1 No error Selected IN value is assigned to OUT
0 K is greater than or equal to the
number of IN parameters No ELSE provided:
OUT is unchanged ELSE provided:
ELSE value assigned to OUT