Omron CX-PROGRAMMER 5.0-FUNCTION BLOCK OPERATION Operation Manual page 171

Function blocks
Table of Contents

Advertisement

Structured Text (ST Language) Specifications
Example 2: Conversion of BIN Data (#0000-#FFFF) to BCD Data
(*check the input parameter "Input_BIN" (BIN data) *)
IF (Input_BIN>=0 & Input_BIN<=16#FFFF) THEN
ENO:=true;
ELSE
ENO:=false;
RETURN;
END_IF;
(*BIN data is divided by 10 four times to get each digit of the BCD data converted from the BIN data*)
DIV_1:=Input_BIN/10;
DIV_2:=DIV_1/10;
DIV_3:=DIV_2/10;
DIV_4:=DIV_3/10;
(*Calculate each digit of the BCD data converted from the BIN data*)
BCD_1:=Input_BIN-10*DIV_1;
BCD_2:=DIV_1-10*DIV_2;
BCD_3:=DIV_2-10*DIV_3;
BCD_4:=DIV_3-10*DIV_4;
(*Calculate the BCD data "Output_BCD" (output parameter) *)
Output_BCD:=BCD_1+BCD_2*16+BCD_3*16*16+BCD_4*16*16*16;
Input_BIN
Restrictions
Nesting
There is no restriction on the number of nests that can be used in IF, CASE, FOR, WHILE, or REPEAT state-
ments.
Data Type Restrictions
• Integers can only be allocated to variables with data types WORD, DWORD, INT, DINT, UINT, UDINT, or
ULINT. For example, if A is an INT data type, A:=1; it possible. If the value is not an integer data type, a
syntax error will occur. For example, if A is an INT data type, a syntax error will occur for A:=2.5;.
• If a real number (floating point decimal data) can only be allocated to variables with data types REAL and
UREAL. For example, if A is a REAL data type, A:=1.5; is possible. If the value is not an real data type, a
syntax error will occur. For example, if A is a REAL data type, a syntax error will occur for A:=2;. Use
A:=2.0;.
• Bits (TRUE, FALSE) can only be allocated to variables with the BOOL data type. For example, if A is a
BOOL data type, A:=FALSE; is possible. If a BOOL data type is not used, a syntax error will occur. For
example, if A is an INT data type, a syntax error will occur for A:=FALSE;.
• Data types must all be consistent within the structured text. For example, if A, B, and C are INT data types,
A:=B+C; is possible. If, however, A and B are INT data types, but C is a REAL data type or LINT data type,
a syntax error will occur for A:=B+C;.
156
(*a number of 10
(*a number of 10
(*a number of 10
(*a number of 10
Output_BCD
0
digit*)
1
digit*)
2
digit*)
3
digit*)
Appendix B

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the CX-PROGRAMMER 5.0-FUNCTION BLOCK OPERATION and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Cx-programmer 5.0Sysmac ws02-cxpc1-e-v50Cs1-hCj1-hCj1m

Table of Contents

Save PDF