EasyManua.ls Logo

Omron CX-PROGRAMMER 5.0-FUNCTION BLOCK OPERATION - Page 171

Omron CX-PROGRAMMER 5.0-FUNCTION BLOCK OPERATION
183 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
156
Structured Text (ST Language) Specifications Appendix B
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; (*a number of 10
0
digit*)
BCD_2:=DIV_1-10*DIV_2; (*a number of 10
1
digit*)
BCD_3:=DIV_2-10*DIV_3; (*a number of 10
2
digit*)
BCD_4:=DIV_3-10*DIV_4; (*a number of 10
3
digit*)
(*Calculate the BCD data "Output_BCD" (output parameter) *)
Output_BCD:=BCD_1+BCD_2*16+BCD_3*16*16+BCD_4*16*16*16;
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;.
Input_BIN Output_BCD

Table of Contents

Related product manuals