![IDEC OpenNet series User Manual Download Page 266](http://html.mh-extra.com/html/idec/opennet-series/opennet-series_user-manual_617384266.webp)
18: P
ROGRAM
B
RANCHING
I
NSTRUCTIONS
O
PEN
N
ET
C
ONTROLLER
U
SER
’
S
M
ANUAL
18-5
DJNZ (Decrement Jump Non-zero)
Valid Operands
For the valid operand number range, see page 6-2.
When T (timer) or C (counter) is used as S2, the timer/counter current value is read out.
Since the DJNZ instruction is executed in each scan while input is on, a pulse input from a SOTU or SOTD instruction
should be used as required.
Example: DJNZ and LABEL
The following example demonstrates a program to store consecutive values 1000 through 1049 to data registers D100
through D149, respectively.
Operand
Function
I
Q
M
R
T
C
D
L
Constant
Repeat
S1 (Source 1)
Decrement value
—
—
—
—
—
—
X
X
—
—
S2 (Source 2)
Label number to jump to
X
X
X
X
X
X
X
X
0-255
—
When input is on, the value stored in the data register or link register designated
by S1 is checked. When the value is 0, no jump takes place. When the value is
not 0, the value is decremented by one. If the result is not 0, jump to address
with label 0 through 255 designated by S2. If the decrement results in 0, no
jump takes place, and program execution proceeds with the next instruction.
DJNZ
S1
*****
S2
*****
M8120 is the initialize pulse special internal relay.
At startup, MOV instructions store initial data.
1049
→
D0 to store the value for the first cycle.
50
→
D1 to determine the jump cycles.
IMOV moves D0 data 1049 to D149 in the first cycle.
DEC decrements D0 data to 1048.
DJNZ jumps to label 255 until D1 value reduces to 0.
LABEL
255
M8120
END
M8120
REP
S1 –
D0
D1 –
D99
IMOV(W)
S2
D2
D1
REP
S1 –
1049
D1 –
D0
MOV(W)
REP
S1 –
50
D1 –
D1
MOV(W)
S/D
D0
DEC(W)
S2
255
S1
D1
DJNZ
1049
D0
Destination: D99 + 50 = D149
1049
D149
50
D1
1st cycle:
1048
D0
Destination: D99 + 49 = D148
1048
D148
49
D1
2nd cycle:
1047
D0
Destination: D99 + 48 = D147
1047
D147
48
D1
3rd cycle:
1046
D0
Destination: D99 + 47 = D146
1046
D146
47
D1
4th cycle:
1001
D0
Destination: D99 + 2 = D101
1001
D101
2
D1
149th cycle:
1000
D0
Destination: D99 + 1 = D100
1000
D100
1
D1
150th cycle:
Phone: 800.894.0412 - Fax: 888.723.4773 - Web: www.clrwtr.com - Email: [email protected]