INTEGER into binary coded WORD value
INT_TO_BCD_WORD converts a binary value of the data type INT into a binary coded decimal integer (BCD) value of the type WORD in order to be able to output BCD values in word format.
Input
Output
Since the output variable is of the type WORD and is therefore comprised of 16 bits, the value for the input variable is limited to 4 digits and must be between 0 and 9999.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
INT_value: INT:=0;
BCD_value_16bit: WORD:=0;
END_VAR
VAR
INT_value: INT:=0;
BCD_value_16bit: WORD:=0;
END_VAR
This example uses variables. You can also use a constant for the input variable.
INT_value of the data type INTEGER is converted into a BCD value of the data type WORD. The converted value is written into BCD_value_16bit.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,INT_TO_BCD_WORD!,Instance,11,1,22,3,,?D?C);
B(B_VARIN,,INT_value,9,1,11,3,);
B(B_VAROUT,,BCD_value_16bit,22,1,24,3,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
BCD_value_16bit:=INT_TO_BCD_WORD(INT_value);
LD |
INT_value |
INT_TO_BCD_WORD |
|
ST |
BCD_value_16bit |