Hitachi HIDIC MICRO-EH Applications Manual page 158

Table of Contents

Advertisement

Syntax of FOR to NEXT
1] A NEXT instruction with the same code number as the
code number n of the FOR instruction is required after
the FOR instruction.
FOR 1 (WR0010)
• NEXT undefined error
Program
The NEXT instruction with
NEXT 2
respect to the FOR instruction
does not exist within the user
Program
program.
• FOR undefined error
Program
The FOR instruction does not exist
NEXT 5
before the NEXT instruction.
Program
FOR 5 (WM04F)
• NEXT to FOR error
Program
The NEXT instruction exists
before the FOR instruction.
2] An overlap of FOR and NEXT instructions with the
same code number n is not allowed.
• FOR duplicate-definition error
FOR 3 (WR10)
A FOR instruction with the same
Program
code number n is programmed.
• NEXT duplicate-definition error
NEXT 3
A NEXT instruction with the same
Program
code number n is programmed.
FOR 3
Note: FOR and NEXT duplicate-
Program
definition errors will occur
NEXT 3
during operation pre-processing.
3] FOR and NEXT must be within the same area.
Program head
FOR 1(WR0001)
Normal scan
FOR 2(WR0002)
END
SB1
Subroutine
NEXT 2
SB1
FOR 3(WR0003)
RTS
SB2
NEXT 3
Subroutine
FOR 4(WR0004)
SB2
RTS
INT0
NEXT 4
Interrupt scan
NEXT 1
RT1
4] Use FOR to NEXT as a nest.
FOR 1(WM001) to NEXT 1 will execute
normally.
FOR 1 (WM001)
Nesting error
Program
When WM002=0
FOR 2 (WM002)
Since FOR 1(WM001) to NEXT 1 is
Program
prioritized, jump will not be performed
over NEXT 1 from FOR 2 to NEXT 2.
NEXT 1
At this time, NEXT 2 generates a FOR
FOR3
Program
2 undefined error.
NEXT 2
When WM002 ≠ 0
FOR 2 will not do anything. Therefore,
NEXT 2 will generate a FOR 2
undefined error.
Chapter 5 Instruction Specifications
5] It is possible to escape from a FOR to NEXT loop
using a jump instruction.
FOR 1 (WM001)
CJMP 10 (X00000)
NEXT 1
LBL10
6] FOR to NEXT may be nested up to 5 levels. When a
subroutine is included, the FOR to NEXT within the
subroutine is counted.
FOR 1(WR0001)
FOR 2(WR0002)
FOR 3(WR0003)
FOR 4(WR0004)
FOR 5(WR0005)
FOR 6(WR0006)
NEXT 6
NEXT 5
NEXT 4
NEXT 3
NEXT 2
NEXT 1
7] Do not include a startup condition between FOR and
NEXT. If a startup condition is required, create a
circuit as shown below:
X00000
JMP 1
FOR 1(WM001)
Program C
NEXT 1
LBL 1
8] The number of repeats may be modified within the
program.
WR0010=20
FOR 1(WR0010)
Program A
R005
WR0010=1
NEXT1
Program B
• When R005 is off
Program B is executed after program A is repeated 20
times.
When R005 is on
The repeat counter WR0010 changes to 1, and since the
NEXT 1 processing subtracts 1 from it, the content of
WR0010 becomes 0. Therefore, the repeating of
program A is terminated and program B is execute
5-108
The FOR 1 to NEXT 1 loop is
escaped when X00000 turns on
before the loop has been repeated
for the set number of repeats
(content of WM001).
• Nesting overflow error
[Operation description]
When X00000 is off, program C is
repeatedly executed for the
number of WM 1 times.
When X00000 is on, program C is
not executed since a jump is
performed from JMP 1 to LBL 1.
The content of WR0010
decrements by 1 and a jump is
performed to FOR 1 (WR0010).

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents