Sei sulla pagina 1di 47

CHNG 5

iU KHIN DNG CHNG TRNH

TS NGUYN C THNH 1
S7-300 LAD

TS NGUYN C THNH 2
S7-300 LAD
If RLO at the input of
the instruction is "1",
the jump to the
network identified
by the specified
jump label is
executed. The jump
direction can be
towards higher or
lower network
numbers.
If RLO = 0, execution
of the program
continues in the next
Jump label must begin by a letter network.
TS NGUYN C THNH 3
S7-300 LAD
If RLO at the input of
the instruction is "0",
the jump to the
network identified by
the specified jump
label is executed. The
jump direction can be
towards higher or
lower network
numbers.
If RLO is "1", execution
of the program
continues in the next
network.
TS NGUYN C THNH 4
S7-300 LAD

If operand "TagIn" has the signal state "1", the "Return"


instruction is executed. Program execution is terminated in the
called block and continues in the calling block. The ENO enable
output of the call function is set to signal state "1".

TS NGUYN C THNH 5
STATUS WORD

/FC (first check)


The /FC bit signal state controls a logic operation string.
A logic operation string begins with an /FC bit signal state of "0" and a binary scan
instruction (first scan). The first scan is the first binary bit logic operation or scan in a
network. This sets the /FC bit to "1". The logic operation string ends with a binary value
assignment (e.g. the "Set" instruction), a conditional jump or a change of block. This
sets the /FC bit to "0".
RLO (result of logic operation)
The status bit RLO is the buffer in binary logic operations.
The CPU transfers the scan results of the first scan to the RLO. The scan results for each
subsequent scan are combined with the RLO saved and the result obtained is then
saved in the RLO. You can set, reset or negate the RLO or save it in the binary result (BR)
using the corresponding instructions.
The RLO is used to control the memory, timer and counter instructions and execute
certain jump instructions.
TS NGUYN C THNH 6
STATUS WORD
The STA status bit is equal to the signal state of the binary
operand queried.
The status of a logic operation that reads memory is
always the same as the value of the addressed bit. The
status of a logic operation that writes to memory (e.g.
the "Set" or "Reset" instructions) always has the same
value as the bit written by the instruction. If the
instruction does not write to memory, the status has
the same value as the addressed bit. The status bit has
no significance for logic operation instructions that do
not access the memory. These instructions set the
status bit to "1". The status bit is not queried by
instructions. It is only evaluated when displaying the
online status of program variables.

TS NGUYN C THNH 7
STATUS WORD
OR (OR bit)
The OR status bit is used when an AND logic operation is executed before an
OR logic operation.
The OR bit is set if the RLO of the AND logic operation is "1". This anticipates
the result of the OR logic operation. Every other binary instruction resets
the OR bit.
OS (Overflow, stored)
The OS status bit saves the set OV status bit.
When the CPU sets the OV status bit, it also sets the OS status bit. However,
while the next properly executed instruction resets the OV bit, the OS
status bit remains set. You are therefore able to query a number range
overflow or, for example, the use of invalid floating-point numbers at a
later stage in the current CPU cycle.
OV (Overflow)
The OV status bit shows a number range overflow or the use of invalid
floating-point numbers.
The OV status bit can be influenced by math functions, conversion
instructions, and floating-point number comparisons.

TS NGUYN C THNH 8
STATUS WORD
CC 0 and CC 1 (condition code bits)
The CC 0 and CC 1 status bits provide information on the
results of the following instructions:
Comparison instructions
Math functions
Word logic operations
Shift and rotate instructions
BR (binary result)
The BR status bit is used to execute the EN/ENO
mechanism for boxes or as a condition in certain jump
instructions (STL). You can influence the BR status bit
using certain instructions (e.g. SAVE).

TS NGUYN C THNH 9
---| |---: Get status bit

TS NGUYN C THNH 10
---| |---: Get status bit

TS NGUYN C THNH 11
---| |---: Get status bit

TS NGUYN C THNH 12
TS NGUYN C THNH 13
S7-300 LAD
The "Motor_DB" data block
is called in network 1. The
number of the data block is
transferred to the DB
register. The "DBX0.0"
operand is queried in
network 2. The signal state
of the DBX0.0 operand is
assigned to the Tag_Output
operand.

TS NGUYN C THNH 14
---(CALL): Call block

TS NGUYN C THNH 15
S7-300 STL

TS NGUYN C THNH 16
S7-300 STL JU JC
L "Tag_1 // Load first comparison value.
L "Tag_2" // Load second comparison value.
>I // Check whether the value of "Tag_1" is greater than the value of
"Tag_2"
JC MyLABEL_1 // if RLO =1 jump to jump label "MyLABEL_1" and
continue with program processing .
L "Tag_3 // Load content of "Tag_3" in ACC 1.
T "Tag_Output_1 // Load contents of ACC 1 in "Tag_1".
JU MyLABEL_2 // Jump to jump label "MyLABEL_2
MyLABEL_1: L "Tag_4 // Load content of the operand "Tag_4 TO
"Tag_2".
T "Tag_2
MyLABEL_2: A "Tag_5
TS NGUYN C THNH 17
S7-300 STL JCN
A "Tag_1
A "Tag_2
JCN MyLABEL // If "Tag_1AND "Tag_2 =0 , jump to
jump label "MyLABEL" and continue program
execution there.
// If the RLO = "1", execute the next instruction.
L "Tag_3
T "Tag_Output //Move "Tag_3 to "Tag_Output
MyLABEL: A "Tag_4

TS NGUYN C THNH 18
S7-300 STL
JCB: Jump if RLO = 1 and save RLO
JNB: Jump if RLO = 0 and save RLO
L "Tag_1
L "Tag_2"
>I
JCB MyLABEL // if "Tag_1 > "Tag_2" Copy current RLO to
BR. jump to jump label "MyLABEL
// If the RLO = "0", execute the next instruction.
L "Tag_3
T "Tag_1 // Move "Tag_3 to "Tag_1
MyLABEL: L "Tag_4
T "Tag_2 // Move "Tag_4 to "Tag_2

TS NGUYN C THNH 19
JBI: Jump if BR = 1
JNBI: Jump if BR = 0
The BR status bit is used to execute the EN/ENO mechanism for boxes
or as a condition in certain jump instructions (STL). You can
influence the BR status bit using certain instructions (e.g. SAVE).
SET // Set RLO to "1" at the start of the block.
SAVE // Transfer signal state of the RLO to the BR bit.
....
// Any program
AN OV // Query OV bit at end of block.
SAVE // If there is an overflow, set BR bit to "0". Set BR to "1" if there is
no overflow.
JBI END // If BR = "1", jump to jump label END.
// If BR = "0", execute the next instruction.
R "Tag_1 // Reset operand "Tag_1" to "0".
END: S "Tag_2 // Set operand "Tag_2" to "1"

TS NGUYN C THNH 20
JO: Jump if OV = 1
JOS: Jump if OS = 1
OV: bit trn, OS: lu gi tr ca OV, khi OV reset th OS gi nguyn,
L "Tag_1 // Load value
L "Tag_2 // Load value
*I // Multiply values "Tag_1 and "Tag_2
JO OVER // If overflow jump to jump label "OVER
T "Tag_Result // Transfer the result of the multiplication to the operand
"Tag_Result".
JU NEXT // Jump to jump label "NEXT
OVER: SET // Set RLO to signal state "1".
R "Tag_Output // Reset operand "Tag_Output" to "0".
NEXT: A "MyTag_1
A "MyTag_2 // "MyTag_1 AND "MyTag_2
S "Tag_Output_2// If RLO = 1, set "Tag_Output_2

TS NGUYN C THNH 21
JOS: Jump if OS = 1
L Tag_1
L "Tag_2
*I
L "Tag_3
+I
L "Tag_4
-I // Tag_1* "Tag_2 + "Tag_3- "Tag_4
JOS OVER // If there is an overflow in one of the three preceding instructions, the status bit
OS is set to "1 , the program resumes at the jump label "OVER".
T "Tag_Result
JU NEXT // Jump to jump label "NEXT" and resume execution of the program there.

OVER: SET // Continue program execution at this point if the condition (OV = "1") is
satisfied.
// Set RLO to signal state "1".
R "Tag_Output// Reset operand "Tag_Output" to "0".

NEXT: A "MyTag_1
A "MyTag_2
S "Tag_Output_2 // If RLO = 1, set the "Tag_Output_2" operand to "1".

TS NGUYN C THNH 22
JZ: Jump if the result is zero
Use the "Jump if the result is zero" instruction to interrupt linear
program execution depending on the status bits CC 0 and CC 1 and
continue at the point marked by the specified jump label.
The situation occurs when one of the following conditions applies:
After processing an arithmetic instruction without overflow,
accumulator 1 has the value "0".
A negative overflow occurs when executing the "Add integers (16 bit)"
(+I) or "Add double integers (32 bit)" (+D) instruction.
The value gradually drops below the permitted range when processing
an arithmetic instruction (floating-point arithmetic) with overflow.
The content of accumulator 2 is equal to the content of accumulator 1
after the execution of a comparison instruction.
The content of accumulator 1 is zero after the execution of a word
logic operation.
The value of the last shifted out bit is "0" after the execution of a shift
instruction.

TS NGUYN C THNH 23
JZ: Jump if the result is zero
L "Tag_Value
SRW 1 // Shift the contents of the right word in accumulator 1 one
place to the right.
JZ ZERO // If the signal state of the last bit shifted is "0", jump to jump
label "OVER
L "MyTag_1
INC 1
T "Tag_Result_1
JU NEXT // Jump to jump label "NEXT
ZERO: L "MyTag_2
INC 1
T "Tag_Result_2
NEXT: A "MyTag_3
A "MyTag_4

TS NGUYN C THNH 24
JN: Jump if the result is not zero
Use the "Jump if the result is not zero" instruction to interrupt linear
program execution depending on the status bits CC 0 and CC 1 and
L "Tag_1 continue at the point marked by the specified jump label.
The situation occurs when one of the following conditions applies:
L "Tag_2 After processing an arithmetic instruction without overflow, the
XOW value of accumulator 1 is not equal to zero.
A negative overflow occurs when processing an arithmetic
JN NOZERO instruction with integers (+I, -I, *I, +D, -D, *D).
.. A positive overflow occurs when executing a math instruction with
integers (+I, -I, *I, /I, +D, -D, *D, /D, NEGI, NEGD).
JU NEXT A positive or negative overflow occurs when processing an
NOZERO: arithmetic instruction with floating-point numbers.
The content of accumulator 2 is not equal to the content of
accumulator 1 after the execution of a comparison instruction.
NEXT: The content of accumulator 1 is not zero after the execution of a
word logic operation.
. The value of the last shifted out bit is "1" after the execution of a
shift instruction.

TS NGUYN C THNH 25
JP: Jump if the result is greater than zero
Use the "Jump if the result is greater than zero" instruction to interrupt linear
program execution depending on the status bits CC 0 and CC 1 and
continue at the point marked by the specified jump label.
The situation occurs when one of the following conditions applies:
After processing an arithmetic instruction without overflow, the value of
accumulator 1 is greater than zero.
A negative overflow occurs when processing an arithmetic instruction with
integers (+I, -I, *I, +D, -D, *D).
A positive overflow occurs when processing an arithmetic instruction with
integers (*I, /I, *D, /D).
A positive overflow occurs when processing an arithmetic instruction with
floating-point numbers.
After the execution of a comparison instruction, the content of accumulator 2
is greater than the content of accumulator 1.
The contents of accumulator 1 are not zero after the execution of a word logic
operation.
The value of the last shifted out bit is "1" after the execution of a shift
instruction.

TS NGUYN C THNH 26
JM: Jump if the result is less than zero
Use the "Jump if the result is less than zero" instruction to interrupt
linear program execution depending on the status bits CC 0 and CC
1 and continue at the point marked by the specified jump label.
The situation occurs when one of the following conditions applies:
After processing an arithmetic instruction without overflow, the value
of accumulator 1 is less than zero.
A negative overflow occurs when processing an arithmetic instruction
with integers (*I, *D).
A positive overflow occurs when processing an arithmetic instruction
with integers (+I, -I, +D, -D, NEGI, NEGD).
A negative overflow occurs when processing an arithmetic instruction
with floating-point numbers.
After the execution of a comparison instruction, the content of
accumulator 2 is less than the content of accumulator 1.

TS NGUYN C THNH 27
JPZ: Jump if the result is greater than
or equal to zero
The situation occurs when one of the following conditions applies:
After processing an arithmetic instruction without overflow, the value
of accumulator 1 is greater than or equal to zero.
A negative overflow occurs when processing an arithmetic instruction
with integers (+I, -I, *I, +D, -D, *D).
A positive overflow occurs when processing an arithmetic instruction
with integers (*I, /I, *D, /D).
A positive overflow occurs when processing an arithmetic instruction
with floating-point numbers.
The value gradually drops below the permitted range when processing
an arithmetic instruction (floating-point arithmetic) with overflow.
After the execution of a comparison instruction, the content of
accumulator 2 is greater than or equal to the content of
accumulator 1.
An instruction for word logic operation was executed.
A shift instruction was executed.

TS NGUYN C THNH 28
JMZ: Jump if the result is less than or equal to zero
After processing an arithmetic instruction without overflow, the value
of accumulator 1 is less than or equal to zero.
A negative overflow occurs when processing an arithmetic instruction
with integers (+I, *I, +D, *D).
A positive overflow occurs when processing an arithmetic instruction
with integers (+I, -I, +D, -D, NEGI, NEGD).
A negative overflow occurs when processing an arithmetic instruction
with floating-point numbers.
The value gradually drops below the permitted range when processing
an arithmetic instruction (floating-point arithmetic) with overflow.
After the execution of a comparison instruction, the content of
accumulator 2 is less than or equal to the content of accumulator 1.
The value of accumulator 1 is equal to zero after processing a word
logic.
The value of the last shifted bit is equal to zero after processing a write
instruction.

TS NGUYN C THNH 29
JUO: Jump if the result is invalid

It is divided by zero with a mathematical instruction


(/I, /D, MOD).
When processing an arithmetic instruction with
floating-point numbers an overflow occurs and
the result value is an invalid floating-point
number.
When processing a comparative instruction with
floating-point numbers an invalid floating-point
number was used or occurred as a result value.
TS NGUYN C THNH 30
JL: Define jump list
Use the instruction "Define jump list" to program a list that consists of
several entries of the instruction "Unconditional jump" (JU). The list
begins directly after the instruction "Define jump list" and may
contain up to 255 entries. The numbering of the jump functions in
the list begins at zero. The jump list must be programmed without
any gaps. The end of the jump list is marked by a jump label that is
specified for the "Define jump list" instruction.
Which jump function of the list executes, depends on the value in the
right byte of accumulator 1. If, for example, the accumulator 1 has
the value "0", the first jump function executes. If the value in
accumulator 1 is "1", the second jump function executes. If the
value in accumulator 1 is greater than the number of list entries,
the "Define jump list" instruction references the end of the list.
The "Jump distributor" instruction is processed independently of
conditions and does not affect the status bits.

TS NGUYN C THNH 31
JL: Define jump list

TS NGUYN C THNH 32
JL: Define jump list
L "Tag_Value // Load jump number in accumulator 1.
JL END // Start of the jump list
JU MyLABEL_1 // If the value is "0", jump to jump label "MyLABEL_1".
JU MyLABEL_2 // If the value is "1", jump to jump label "MyLABEL_2"
JU MyLABEL_3 // If the value is 2", jump to jump label "MyLABEL_3"
END: L "MyTag_1// End of the jump list
// Any program
MyLABEL_1: ... // Jump label "MyLABEL_1"
// Any program
JU NEXT // Jump to jump label "NEXT" and resume execution of the program there.
MyLABEL_2: .. // Jump label "MyLABEL_2"
// Any program
JU NEXT // Jump to jump label "NEXT" and resume execution of the program there.
MyLABEL_3: ... // Jump label "MyLABEL_3"
// Any program
JU NEXT // Jump to jump label "NEXT" and resume execution of the program there.
NEXT: ... // Jump label "NEXT"

TS NGUYN C THNH 33
LOOP: Loop
The instruction interprets the right word of accumulator 1 as an unsigned 16-bit
integer. During execution the instruction first decrements the content of
accumulator 1 by one. If the value in accumulator 1 after the decrement is not
zero, the jump is executed at the specified jump label. If the value is zero, the jump
is not executed and the processing of the program is resumed with the next
instruction. The value in accumulator 1 therefore specifies the number of program
loops that have to be executed. This number has to be saved in a loop counter.
The "Loop" instruction is programmed according to the following general outline:
L <number>
<jump label>:
T <loop counter>
... Any program
L <loop counter>
LOOP <jump label>
The operand "number" contains the number of the loop cycles. The operand "Loop
counter" contains the number of the loop cycles still to be executed. At the end of
the program loop, the content of the loop counter is loaded in accumulator 1 and
decremented by one by the instruction. The jump to the jump label at the start of
the program loop is executed if the value in the accumulator is not equal to zero
after the decrement.

TS NGUYN C THNH 34
LOOP

TS NGUYN C THNH 35
Loop Example
L 20 //Load number of time loop will execute into the right word of
accumulator 1.
L1
T "MyTag_1
START: T "Tag_Counter // Start of the jump list, Transfer contents of
accumulator 1 to the loop counter.
L "MyTag_1
L "MyTag_2
*D
T "MyTag_1
L "Tag_Counter // Load value of the loop counter into accumulator 1.
LOOP START // Decrement value in accumulator 1 by one, // Jump to
the start of the program loop if the value is not equal to zero, // If
the value is zero, execute the next instruction.
// "MyTag_1 = ("MyTag_2)20

TS NGUYN C THNH 36
OPN: Open global data block
OPNDI: Open instance data block

OPN "GlobalDataBlock // Open global data


block.
L %DBW0 // Load data word DBW0 of the
opened global data block into accumulator 1.
T "MyTag // Transfer contents of accumulator 1
to the operand "MyTag_1".

TS NGUYN C THNH 37
BE: Block end
L "Tag_Value_1
SIN
L "Tag_Value_2
*R
L "Tag_Value_3
*R
BE
// End block

TS NGUYN C THNH 38
BEC: Conditional block end
BEU: Unconditional block end
L "Tag_1
L "Tag_2
>I
A "Tag_Input
BEC // End block if condition satisfied (RLO =
"1").
T "Tag_Result

TS NGUYN C THNH 39
CALL: Call block
CALL "MyFunction"
Input_1 := "Tag_Input_1",
Input_2 := "Tag_Input_2"
Output_1 := "Tag_Output_1"
Output_2 := "Tag_Output_1
CALL "MyFunctionBlock", "MyFB_DB"
Value_1 := "Tag_Value_1"
Value_2 := "Tag_Value_2"
Output := "Tag_Output
CALL "LIMIT"
MN := "Tag_LowLimit"
IN := "Tag_InputValue"
MX := "Tag_HighLimit"
OUT := "Tag_Output"

TS NGUYN C THNH 40
CC: Conditional block call
A "Tag_1
CC "MyFunction"
// If RLO = 1, call the function MyFunction.
A "Tag_2"
// If "Tag_1 AND "Tag_2=1 call the function
block MyFunctionBlock.
CC "MyFunctionBlock

TS NGUYN C THNH 41
S7-1200 LAD

TS NGUYN C THNH 42
JMP_LIST: Define jump list
You can use the "Define jump list" instruction to define several conditional
jumps and continue the program execution in a specific network
depending on the value of the K parameter.
You define the jumps with jump labels (LABEL), which you specify at the
outputs of the instruction box. The number of outputs can be
expanded in the instruction box. You can declare up to 32 outputs
when you use a CPU S7-1200 and a maximum of 99 outputs when you
use a CPU S7-1500.
The numbering of the outputs begins with the value "0" and continues in
ascending order with each new output. Only jump labels can be
specified at the outputs of the instruction. Instructions or operands
cannot be specified.
The value of the K parameter specifies the number of the output and thus
the jump label where the program execution is to be resumed. If the
value in the K parameter is greater than the number of available
outputs, the program execution is resumed in the next network of the
block.
The "Define jump list" instruction is only executed if the signal state is "1"
at the EN enable input.

TS NGUYN C THNH 43
JMP_LIST: Define jump list

TS NGUYN C THNH 44
SWITCH: Jump distributor
You can use the "Jump distributor" instruction
to define multiple program jumps to be
executed depending on the result of one or
more comparison instructions.
You specify the value to be compared in the K
parameter. This value is compared with the
values that are provided by the various inputs.
You can select the comparison method for
each individual input. The availability of the
various comparison instructions depends on
the data type of the instruction.
TS NGUYN C THNH 45
SWITCH: Jump distributor

TS NGUYN C THNH 46
SWITCH: Jump distributor

TS NGUYN C THNH 47

Potrebbero piacerti anche