For: repeat start next: repeat end – KEYENCE Visual KV Series User Manual

Page 149

Advertising
background image

2.4 Instruction Details

1

2

3-125

Chapter 2 Instructions

Example

Coding

Description

Use FOR-NEXT instructions in a subroutine program (between SBN and RET) to
initialize data memory (DM0100 through DM0149) when the operation is started.
The indirect addressing method is used to change the data memory, so the initializa-
tion is completed when the TM02 value becomes "50 + 1" between the FOR and
NEXT instructions.

➮ "Indirect addressing" (p. 3-127)

The FOR instruction takes either of the following two types of operands: the
number of repetitions or the location (DM No.) of the data memory containing the
number of repetitions.

Define the program to be repeated between the FOR and NEXT instructions.

The FOR instruction repeats the desired sequence by the specified number of
times during each scan time.

FOR: Repeat Start

NEXT: Repeat End

Executes program between FOR and NEXT
by number of times specified by operand.

Represents end of repetition.

Line No.

Instruction

Operand

Line No.

Instruction

Operand

0000

LD

2008

0107

FOR

#00050

0001

CALL

00

0108

LD

2002

:

:

0109

STA

#TM02

0099

END

0110

CON

0100

SBN

00

0111

INC

TM02

0101

LD

2002

0112

NEXT

0102

LDA

#00100

0113

RET

0103

CON

:

0104

STA

TM02

:

0105

CON

:

0106

LDA

#00000

0199

ENDH

FUN

FUN

SET

1

ANL

2

O R

9

ORB

6

NEXT

FOR

nnnn

Specify the first DM No.

Specify the number of DMs to be
initialized.

2008

#00100

LDA

2002

2002

00

CALL

END

SBN

00

#00050

FOR

NEXT

RET

ENDH

TM02

STA

#00000

LDA

#TM02

STA

TM02

INC

(DM100)

:

:

FOR / NEXT

KVNKA Chap 02_4bP.p65

08.3.11, 0:00 PM

125

Advertising