Vous êtes sur la page 1sur 14

Status Bit-Dependent Instructions

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.1

Information and Training Center Knowledge for Automation

Register and Memory Areas of an S7-CPU


Accumulators
ACCU4 only S7-400 ACCU3 ACCU2 ACCU1
32 Bit

Load Memory
32 Bit 32 Bit 32 Bit Logic Blocks Data Blocks

Work Memory
L, A, O,...
Logic Blocks Data Blocks

Address Register
AR1 AR2
32 Bit 32 Bit

T, S, =,...

I/O Area System Memory


Process-image input table Process-image output table Bit memories Timers Counters Local Data Stack Interrupt Stack Block Stack

Data Block Register


open DB open DI
16 Bit

DB Length DI Length
16 Bit

Status Word
Status Bits
16 Bit

S7-CPU Register SIMATIC S7


Siemens AG 1999. All rights reserved.

S7-CPU Memory Areas


Date: File: 04.03.2014 PRO2_01E.2
Information and Training Center Knowledge for Automation

Status Word Structure


Meaning of the bits in the status word
Bit
0 1 2 3 4 5 6 7 8 9...15

Assignment
/FC RLO STA OR OS OV CC 0 CC 1 BR Unassigned

Value
20 21 22 23 24 25 26 27 28 29 ..210

Meaning
First check bit Result of logic operation Status Or Stored overflow Overflow Condition code Condition code Binary result

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.3

Information and Training Center Knowledge for Automation

Checking the Status Bits


Checking in STL

A OV A OS A BR

Scan overflow display Scan stored overflow Scan BR flag

Checking the Condition Code (CC0, CC1)


A == 0 Result equal to 0 A > 0 Result greater than 0 A <> 0 Result not equal to 0

A =< 0 Result less than or equal to 0 etc.


A UO Instruction is unordered

Checking in LAD and in FBD


OV
M 4.0 S >0 M 4.0 S

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.4

Information and Training Center Knowledge for Automation

Instructions with Status Bits


Instruction

Meaning
Set RLO to "1" Set RLO to "0" Invert RLO

Example
SET = M 0.1 CLR //RLO-1 //RLO-0

SET CLR NOT

O Manual operation; O Automatic operation; NOT; = Operating modes = M0.0

I 1.0

I 1.1

I 1.2

SAVE

Save RLO in binary result Check binary result

||
BR

||
Q 4.2

||

(SAVE)
Q 5.0

A BR

||

||

()

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.5

Information and Training Center Knowledge for Automation

BR Bit and ENO in a Block Call or Complex Functions


LAD
Network 1: Cyclic Program I0.0 EN FC23 ENO M10.0

STL
Network 1: Cyclic Program A I 0.0 JNB _001 CALL FC 23 Step_bit_memory Step_display :=QW12 _001: A BR = M 10.0

( )
QW12

:=M

MW10

Step_bit Step_dis _memory play

Network 2: ??? I0.1 EN 345 987 IN1 IN2 MUL_I ENO M10.1

( )
MW100

OUT

Network 2: ??? A I 0.1 JNB _002 L 345 L 987 *I T MW 100 AN OV SAVE CLR _002: A BR = M 10.1

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.6

Information and Training Center Knowledge for Automation

Jump Functions Dependent on Status Bits


JU Label1) JC Label1) JCN Label1)

Jump unconditional Jump if "RLO" bit =1 Jump if "RLO" bit = 0

JCB Label1)
JNB Label1) JBI Label1) JNBI Label1) JO Label1) JOS Label1)

Jump if "RLO" bit = 1 and save RLO


Jump if "RLO" bit = 0 and save RLO Jump if "BR" bit = 1 Jump if "BR" bit = 0 Jump if "OV" bit in status word =1 Jump if "OS" bit in status word =1
1) Label

can consist of 4 alpha-numeric characters

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.7

Information and Training Center Knowledge for Automation

Jump Functions Dependent on Condition Codes

JZ Label1)

Jump if in the status word bit "CC 1"=0 and "CC 0"=0 (Result = 0)

JN Label1)
JP Label1) JM Label1) JPZ Label1) JMZ Label1) JUO Label1)

Jump if in the status word bit "CC 1" is not equal to "CC 0" (Result <> 0)
Jump if in the status word bit "CC 1"=1 and "CC 0"=0 (Result > 0) Jump if in the status word bit "CC 1"=0 and "CC 0"=1 (REsult < 0) Combines the jumps JZ and JP (Result >= 0) Combines the jumps JM and JZ (Result <= 0) Jump if: invalid Real number or division by zero
1) Label

can consist of 4 alpha-numeric

characters

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.8

Information and Training Center Knowledge for Automation

Programming Jump Distributors


Mode of Operation
Load jump number JL OVER JU M_0

Example: Jump distributor with 3 entries


L Recipe no JL OVER JU Rec0 JU Rec1 JU Rec2 OVER: JU ERROR ... Rec0: L DBW4 ... Rec1: L DBW6 ... Rec2: L DBW8 ... ERROR: ... CLR // Load recipte no. // Jump distributor with 3 entries // Jump to recipe no. 0 (ACCU1 = 0) // Jump to recipe no. 1 (ACCU1 = 1) // Jump to recipe no. 2 (ACCU1 = 2) // Jump if ACCU1 > 2

. . .

JU M_n OVER: M_0: Instructions if ACCU1 > n Instructions if ACCU1 = 0

. . .
M_n: Instructions if ACCU1 = n

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.9

Information and Training Center Knowledge for Automation

Programming Loop Instructions


Mode of Operation
Initialize loop counter NEXT: Transfer to loop counter Code section to be executed several times Load loop counter in ACCU1.

Example: Loop instruction with 4 scans


L +4 NEXT: T MW10 // Load loop counter // Beginning of the loop

.
. . L MW10

// Code
// Code // Code // Load loop counter again // Loop counter -1 and // jump to jump label // NEXT if Accu 1> 0

Yes

LOOP NEXT
decrement ACCU1, ACCU1 <> 0 ?

LOOP NEXT

No Continue

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.10

Information and Training Center Knowledge for Automation

Instructions for Block End

BE

Block End

BEU

Block End Unconditional (within a block)

BEC

Block End Conditional (dependent on the RLO)


(RET) in the LAD programming language

RET

in the FBD programming language

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.11

Information and Training Center Knowledge for Automation

Exercise 1.1: Jump After a Subtraction


Pushwheel button 1 2 3 4 Toggle switch on the Simulator 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0
215 27 20

convert to BTD DINT

BTD

convert to DINT

-D
Pos. result (>=0) Neg. result [JM Label] Delete display Write the value of IW 0 in the display Display:

Decade switch: Toggle switch:

S7-300: IW4 (IW2, 32-Bit Mod.) S7-400: IW 30 S7-300: IW0 (IW0) S7-400: IW28

S S

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.12

Information and Training Center Knowledge for Automation

Exercise 1.2: Jump After a Multiplication


Pushwheel button 1 2 3 4 Toggle switch on the Simulator 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0
215 27 20

convert to BTD DINT

BTD

convert to DINT

*I
No overflow Overflow [JO Label] Delete display DTB Convert result to BCD

Output result to the display Display:

Decade switch: Toggle switch:

S7-300: IW4 (IW2, 32-Bit Mod.) S7-400: IW30 S7-300: IW0 (IW0) S7-400: IW28

S S

SIMATIC S7
Siemens AG 1999. All rights reserved.

Date: File:

04.03.2014 PRO2_01E.13

Information and Training Center Knowledge for Automation

Exercise 1.3: Programming a Jump Distributor


Function:
Pushwheel button

1
1 2 3 4 5

[ JL Label]

Motor_let run to the right


Motor_let run to the left Motor off Horn on Horn off

Label: Jump using Jump to List

Addresses: Motor_right: Motor_left: Horn:

S7-300 (16-Bit) Q20.5 Q20.6 Q20.7


Date: File:

S7-300 (32-Bit) Q8.5 Q8.6 Q8.7


04.03.2014 PRO2_01E.14

S7-400 Q40.5 Q40.6 Q40.7


Information and Training Center Knowledge for Automation

SIMATIC S7
Siemens AG 1999. All rights reserved.

Vous aimerez peut-être aussi