Logical block used to perform the set of a specific bit in a field.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_IN_OUT |
Data |
BYTE USINT SINT WORD UINT INT DWORD UDINT DINT |
Variable whose bit will be changed |
VAR_INPUT |
EN |
BOOL |
Block enabling |
Position |
BYTE USINT |
Position of the bit that will be changed |
|
VAR_OUTPUT |
DONE |
BOOL |
Operation successful |
Operation
This block when it has a TRUE value in EN, sets the bit indicated in Position in the Data variable that is forwarded to the output already with its updated value.
When EN has FALSE value, Data remains unchanged.
The DONE variable receives the same EN value, except when there is an error in the set of the bit, then getting a FALSE value.
|
NOTE! It is important to notice that Position is within the range of values of bits corresponding to variable type in Data. For example: if Data is a BYTE, it has 8 bits, and Position must contain a value between 0 and 7. |
Block Flowchart

Example in Ladder

The example above sets the bit of AUX zero position, whose initial value is 153 (1001 1001, in binary). Since this bit already had TRUE value, nothing has changed.

The example above sets the bit in position three of AUX by changing its binary value and, therefore, its decimal representation.

The example above sets the bit in position fifteen of AUX. Since AUX is a variable BYTE type, it has only eight bits. Thus, the example above creates a runtime error in the block and therefore the output is not enabled.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR AUX : BYTE := 2#1001_1001; POS : BYTE := 2; END_VAR
DO1 := FB_SETBIT( EN:=DI1, Data:=AUX, Position:=POS);
|
|---|