EasyManua.ls Logo

Omron NJ Series - Page 282

Omron NJ Series
668 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...
6-95
6 Programming
NJ-series CPU Unit Software User’s Manual (W501)
6-5 Programming Languages
6
6-5-3 Structured Text Language
Do not write code that directly modifies the FOR variable inside the FOR construct. Unintended
operation may result.
Example:
You can write any of the statements on multiple lines. Separate statements with a semicolon (;).
You can omit BY<increment/decrement>. If it is omitted, the statement is executed with an incre-
ment value of 1.
You can specify an integer (SINT, INT, DINT, LINT, USINT, UINT, UDINT, or ULINT) variable or
integer value for the <initial_value>,<end_value>, and <increment/decrement>. You can also
specify a function that returns an integer value.
Example 1: A value of 100 is assigned to array variable elements SP[n]. The FOR variable is
variable n, the initial value is 0, the end value is 50, and the increment is 5.
Example 2: The total of elements DATA[1] through DATA[50] of array variable elements DATA[n]
is calculated and the result is assigned to the variable SUM.
Example 3: The maximum and minimum values of elements DATA[1] through DATA[50] of array
variable elements DATA[n] are found. The maximum value is assigned to the MAX
variable, and the minimum value is to the MIN variable. The value of DATA[n] is from
0 to 1,000.
FOR i:=0 TO 100 BY 1 DO
X[i]:=0;
i:=i+INT#5;
END_FOR;
FOR n := 0 TO 50 BY 5 DO
SP[n] := 100;
END_FOR;
IF a THEN
FOR n := 0 TO 50 BY 1 DO
DATA[n]:= 1 ;
END_FOR;
FOR n := 0 TO 50 BY 1 DO
SUM:= SUM + DATA[n] ;
END_FOR;
a:=FALSE;
END_IF;
MAX :=0;
MIN :=1000;
FOR n :=1 TO 50 BY 1 DO
IF DATA[n] > MAX THEN
MAX :=DATA[n];
END_IF;
IF DATA[n] < MAX THEN
MIN :=DATA[n];
END_IF;
END_FOR;

Table of Contents

Other manuals for Omron NJ Series

Related product manuals