99BProgramming concepts
6.5 Programming language
S7-1200 Programmable controller
148
System Manual, 11/2011, A5E02486680-05
Type
Operation
Operator
Priority
Modulo
MOD
4
Addition
+
5
Subtraction
-
5
Less than
<
6
Less than or equal to
<=
6
Greater than
>
6
Greater than or equal to
>=
6
Equal to
=
7
Comparison
Not equal to
<>
7
Negation (unary)
NOT
3
AND logic operation
AND or &
8
Exclusive OR logic operation
XOR
9
Bit logic
OR logic operation
OR
10
Assignment
Assignment
:=
11
As a high-level programming language, SCL uses standard statements for basic tasks:
●
Assignment statement: :=
●
Mathematical functions: +, -, *, and /
●
Addressing of global variables (tags): "<tag name>" (Tag name or data block name
enclosed in double quotes)
●
Addressing of local variables: #<variable name> (Variable name preceded by "#" symbol)
The following examples show different expressions for different uses.
"C" := #A+#B;
Assigns the sum of two local variables to a tag
"Data_block_1".Tag := #A;
Assignment to a data block tag
IF #A > #B THEN "C" := #A;
Condition for the IF-THEN statement
"C" := SQRT (SQR (#A) + SQR (#B));
Parameters for the SQRT instruction
Arithmetic operators can process various numeric data types. The data type of the result is
determined by the data type of the most-significant operands. For example, a multiplication
operation that uses an INT operand and a REAL operand yields a REAL value for the result.
Control statements
A control statement is a specialized type of SCL expression that performs the following
tasks:
●
Program branching
●
Repeating sections of the SCL program code
●
Jumping to other parts of the SCL program
●
Conditional execution
The SCL control statements include IF-THEN, CASE-OF, FOR-TO-DO, WHILE-DO,
REPEAT-UNTIL, CONTINUE, GOTO, and RETURN.