Introduction to programming with SCL

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 285 - 289)

This chapter describes programming with Structured Control Language (SCL); it uses examples to show how the program functions are represented in SCL. You can find a description of the individual functions, e.g. comparison functions, in Chap- ters 10 “Basic functions” on page 328, 11 “Digital functions” on page 355, and 12

“Program flow control” on page 406.

Use of the program and symbol editor, which generally applies to all programming languages, is described in Chapter 6 “Program editor” on page 178.

SCL is used to program the contents of blocks. What blocks are, and how they are created, is described in Chapters 5.3.1 “Block types” on page 125 and 6.3 “Program- ming a code block” on page 183.

9.1.1 Programming with SCL in general

You use SCL to program the control function of the programmable controller – the user program or control program. The user program is organized in different types of blocks.

Fig. 9.1 shows the SCL program for a FIFO register. With a rising edge at #Write, this block writes the value present at the #Input parameter into a FIFO register. With a rising edge at #Read, the value at #Output is output again. The values are read out in the order in which they were written into the register (FIFO, first in first out). The register can be emptied using #Delete. The two displays #Full and #Empty show the status of the register (#Full and #Empty are each set following writing or reading).

The block works with a write pointer and a read pointer.

The program editor constructs an SCL program line by line. You commence with the first statement in the first line. Each SCL statement is concluded by a semicolon.

You can write several statements in one line, or one statement can occupy several lines.

You can make the SCL program clearer and easier to read by using comments and empty lines. Comments and empty lines have no influence on the function of the SCL program.

Line comments commence with two slashes and terminate at the end of the line.

Block comments commence with left parenthesis and asterisk, can extend over sev- eral lines, and terminate with asterisk and right parenthesis.

In order to program an SCL statement, use the keyboard to enter the statements in a line of the input field. Dragging the statement with the mouse from the program

elements catalog is of advantage with SCL if you import functions with a parameter list into your program. To call self-created blocks, drag the blocks from the Program blocks folder in the project tree into a line.

Fig. 9.1 Example of a block with SCL program

9.1.2 SCL statements and operators

The SCL program consists of a sequence of individual STL statements. Fig. 9.2 shows which types of SCL statements exist.

The simplest case with a Value assignment is that the content of a tag is transferred to another tag. Control statements guide program execution, for example with pro- gram loops. Block calls are used to continue program execution in the called block.

Operators

An expression represents a value. It can comprise a single address (a single tag) or several addresses (tags) which are linked by operators.

Example: “a + b” is an expression; “a” and “b” are addresses, “+” is the operator.

The sequence of logic operations is defined by the priority of the operators and can be controlled by parentheses. Mixing of expressions is permissible providing the data types generated during calculation of the expression permit this.

SCL provides the operators specified in Table 9.1. Operators of equal priority are processed from the left to the right.

Table 9.1 Operators with SCL

Operation Name Operator Priority

Parentheses Left parenthesis, right parenthesis (, ) 1

Arithmetic Power ** 2

Unary plus, unary minus (sign) +, – 3

Multiplication, division *, /, DIV, MOD 4

Addition, subtraction +, – 5

Comparison Less than, less than-equal to, greater than, greater than-equal to

<, <=, >, >= 6

Equal to, not equal to =, <> 7

Binary logic operation Negation (unary) NOT 3

AND logic operation AND, & 8

Exclusive OR XOR 9

OR logic operation OR 10

Assignment Assignment := 11

“Unary” means that this operator has a fixed assignment to an address

Fig. 9.2 Types of SCL statements Label

Label

Label

Label

SCL statement

Variable

xxx IF CASE FOR WHILE REPEAT

#Result

#Result

#Result

Statement sequence

Block name (parameter list) Statement sequence

Variable := Block name (parameter list) Statement sequence Statement sequence Statement sequence Statement sequence Expression

END_xxx END_IF END_CASE END_FOR END_WHILE END_REPEAT

#VariableAND#Variable

#Variable>=#Variable

#Variable+#Variable :=

:=

:=

:=

;

;

;

;

;

;

;

;

;

;

;

;

; //

//

//

//

:

:

:

:

General SCL statement

Value assignment with assignment operator

Block call

Logical expression

IF branch CASE branch FOR loop WHILE loop REPEAT loop

Comparison expression Arithmetic expression

Comment

Comment

Comment

Comment SCL statement

Value assignment

Control statement

Block call SCL statements

An SCL statement consists of a jump label with subsequent colon and the actual statement, which is terminated by a semicolon. The statement can extend over several lines. The statement can be followed by a (line) comment, which is commenced by two slashes and extends up to the end of the line. The jump label (including colon) and the line comment can be omitted.

A value assignment transfers the value of an expression to a tag. An expression can be a single tag or a formula for calculating a value. A formula links the tags by means of operators.

Depending on the type of logic operation, a distinction is made between arithmetic expressions, comparison expressions, and logical expressions.

A control statement controls the processing sequence in the program by means of branching and program loops which are processed repeatedly. A control statement begins with a keyword (xxx) and is terminated by END_xxx.

The call of a block without return value consists of the block name and the following parameter list in parentheses. If the block has a return value, the block call following an assignment operator is present in a value assignment or an expression.

Most extended statements in the Program Elements catalog are calls of system blocks with return value.

Control statement

Expressions

An expression is a formula for calculating a value and consists of addresses (tags) and operators. In the simplest case, an expression is an address, a tag, or a constant.

A sign or a negation can also be included.

An expression can consist of addresses that are linked together by operators.

Expressions can also be linked by operators. Expression can therefore have a very complex structure. Parentheses can be used to control the processing sequence in an expression.

The result of an expression can be assigned to a tag or a block parameter or used as a condition in a control statement.

Expressions are distinguished according to the type of logic operation into arithme- tic expressions, comparison expressions, and logic expressions.

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 285 - 289)

Tải bản đầy đủ (PDF)

(577 trang)