• 沒有找到結果。

Conditional jump, unconditional jump (CJ, SCJ, JMP)

6. BASIC INSTRUCTIONS

6.5.1 Conditional jump, unconditional jump (CJ, SCJ, JMP)

Available Device

Bit device Word (16-bit) device Constant Pointer Level Carry flag Error flag

X Y M L S B F T C D W R A0 A1 Z V K H P I N

Digit specification Index

M9012 (M9010, M9011)

P O O O

Functions CJ

(1) Executes the program of specified pointer number when the jump command is on.

(2) Executes the program of the next step when the jump command is off.

SCJ

(1) Executes the program of specified pointer number, starting at the next scan, when the jump command changes from off to on.

(2) Executes the program of the next step when the jump command is off or changes from off to on.

Jump commands

Applicable

CPU All CPUs

CJ P**

SCJ

JMP P**

Jump P**

destination pointer number (Label)

P** * P255 indicates END and cannot

be used as a label.

Jump command

CJ Executed per scan

Jump command

SCJ 1 scan Executed per scan

P** Pointer number of jump destination (P0 to P255) Setting data

ON OFF

ON OFF

JMP

(1) Executes the program of specified pointer number unconditionally.

Consider the following when the jump instructions are used.

(2) Even if the timer, of which coil is on, is jumped by the CJ, SCJ, or JMP instruction after the coil of timer is turned on, the timer continues counting.

(3) If the OUT instruction is jumped by CJ, SCJ or JMP, coil status is held unchanged.

(4) When a jump is made to a memory location by CJ, SCJ, or JMP, the scan timer is shortened.

(5) The CJ, SCJ, and JMP instructions are also capable of jumping to a step with lower number. However, it is necessary to exit this closed loop before the watch dog timer times out.

(6) The device jumped by CJ, SCJ, or JMP does not change.

(7) The label (P**) occupies one step.

( )

Exits the loop when X7 is turned ON.

( )

( )

( )

When XB turn on, jump is made to the label P19.

Even if XB and C turn on/off during the execution of CJ instruction, Y43 and 49 do not change.

10

6 − 60

Operation Errors In the following cases, operation error occurs and the PC stops its operation.

• When there are mult. contacts of the same labels, a jump has been made to that label by the CJ, SCJ, or JMP instruction.

• There is no label at the jump destination of CJ, SCJ, or JMP instruction.

• Jump has been made to a label located below the END instruction.

• Jump has been made to a step between FOR and NEXT.

• Jump has been made into a subroutine.

Program Examples SCJ

(1) Program which causes a jump during the next scan to END when XC turns on.

( )

( )

( )

0

4

11 X00C

X00C

X00B X013

X017

SCJ P255

Y093

Y099

Y083

When XC turns on, jump is made from the next scan to END.

(P255 represents END.)

Executed when XC turns off or turns from off to on.

END

Coding

0 LD X00C

1 SCJ P255

4 LDI X00C

5 MPS

6 AND X013

7 OUT Y093

8 MPP

9 AND X017

10 OUT Y099

11 LD X00B

12 OUT Y083

13 END

(2) Program which causes a jump during the next scan to P3 when XC turns on.

CJ

(3) Program which causes a jump to the END instruction when X9 turns on.

( )

( )

0

4

6 P3

X00C

X030

X041

SCJ P3

Y06F

Y07E

Coding

0 LD X00C

1 SCJ P3

4 LD X030

5 OUT Y06F

6 P3

7 LD X041

8 OUT Y07E

9 END

( )

( )

0

2 X009

6

7

CJ P255 X000

X011

Y030

FEND

Y041

Coding

0 LD X000

1 OUT Y030

2 LD X009

3 CJ P255

6 FEND

7 LD X011

8 OUT Y041

9 END

6 − 62 6.5.2 Subroutine call, return

(CALL, CALLP, RET)

Available Device

Bit device Word (16-bit) device Constant Pointer Level Carry flag Error flag

X Y M L S B F T C D W R A0 A1 Z V K H P I N

Digit specification Index

M9012 (M9010, M9011)

P O O O

Functions CALL, CALLP

(1) Executes the subroutine program specified by the pointer (P**).

(2) Up to five levels of nesting of the CALL/CALLP instruction are allowed.

RET

(1) Executes the sequence program located at the next step to the CALL(P) instruction when the RET instruction is executed.

(2) Indicates the end of subroutine program.

POINT

For the PC CPUs shown below, setting indicated below is required.

• A0J2HCPU, AnSCPU, AnSHCPU,A2CCPU, AnCPU, AnNCPU, A3HCPU, A3MCPU, A3VCPU

In a sequence between the RET instruction in a subroutine program and the END instruction at the end of a sequence program, a dummy circuit must always be set. Otherwise, the PC will fail to operate correctly.

(A NOP instruction has the same effect. However, take it into consideration that "NOP batch deletion" must not be executed by a peripheral device.)

Applicable

CPU All CPUs

Subroutine execution commands

P**

RET CALL

P**

Head pointer number of subroutine program (P0 to 253)

Setting data

Subroutine program P**

CALLP Call of subroutine

program Head pointer number (label) of subroutine program

Return of subroutine

program P**

Execution The execution conditions of CALL and CALLP are a shown below.

Conditions

When a program uses the PLS and PLF instructions in the subroutine, and when the ON/OFF time of a subroutine execution designation signal is set shorter than the scan time, the device designated with (D) of the subroutine PLS and PLF instructions may sometimes remain turned ON more than 1 scan.

Operation Errors In the following cases, operation error occurs and the PC stops operation.

• After the CALL(P) instruction is executed, the END(FEND) instruction has been executed before executing the RET instruction.

• The RET instruction has been executed before executing the CALL(P) instruction.

• The label P255 has been called by the CALL(P) instruction.

• The JMP instruction was executed to exit from a subroutine before execution of the RET instruction.

• Nesting is of six or more levels.

Program Example CALL , RET

(1) Program which executes the subroutine program when X1 changes from off to on.

OFF

ON

Executed per scan

Executed per scan

Executed only once

Executed

3 CALLP P33

6 LD X009

7 OUT Y013

8 FEND 9 P33

10 LD X000

11 OUT Y033

12 OUT Y034

13 RET 14 END

When the ON/OFF time is shorter than the scan time:

When the ON/OFF time is longer than the scan time:

X0

6 − 64 6.5.3 Interrupt enable, disable, return

(EI, DI, IRET)

The EI and DI instructions used with the AnN, AnS, AnSH, A1FX, A0J2H and A73 vary in function with status of special relay M9053, as mentioned below.

When M9053 is ON: Link refresh enable/disable (See Section 6.7.2 for details.) When M9053 is OFF: Interrupt enable/disable

Available Device

Bit device Word (16-bit) device Constant Pointer Level Carry flag Error flag

X Y M L S B F T C D W R A0 A1 Z V K H P I N

Digit specification Index

M9012 (M9010, M9011)

Functions DI

(1) Disables the interrupt program until the EI instruction is executed so that interrupt signals are ignored.

(2) When the PC CPU is RESET, interrupt program execution is disabled.

EI

(1) Enables the interrupt program.

AnS AnN AnSH

An A1FX A3H

A3M A3V AnA

AnU, A2AS

A52G A73 A3N board Applicable

CPU

O O X O O X

Remark * EI and DI instructions are valid only when special relay M9053 is OFF.

EI Program execution continues

IRET Interrupt program Required to the AnN, AnS,

AnSH, A1FX, A0J2H, A73 and A3N board

Interrupt pointer (10 to 31) (Label)

Any interrupt signal occuring between DI and EI instructions, is disabled until the processing between the DI and EI instructions is completed after which the interrupt program is run.

* * * * *

IRET

(1) Indicates the termination of processing of interrupt program.

(2) Performs the processing of counter for interruption and returns the processing to the sequence program after the RET instruction is executed.

With the CPUs other than A3H, A3M, AnA, A2AS, AnU, QCPU-A (A Mode) and A2USH board interrupt counter processing is performed.

POINTS

(1) When a counter is used in the interrupt program, use the counter for interruption.

The A3H, A3M, AnA, A2AS, AnU, QCPU-A (A Mode) and A2USH board do not have any counter which may be used in the interrupt program.

(2) The pointer for interruption occupies one step.

(3) For the interrupt conditions, refer to the ACPU Programming Manual (Fundamentals).

(4) During the execution of interrupt program, DI (interruption inhibition) is set.

Do not allow multiple interrupt programs to be run simultaneously. This can be prevented by using the EI instruction in the interrupt programs.

(5) If the EI or DI instruction is contained in the MC instruction, such EI and DI are executed without regard to execution of the MC instruction.

Operation Error If the IRET instruction is executed prior to the run of interrupt program, the PC stops its operation.

( )

( )

I10 50

X00C

X005

Y010

Y030

IRET 53

55 Stored into step 50.

Sequence program IRET

FEND

IRET I13

When IRET instruction is executed, PC stops operation.

Interrupt program

6 − 66 Program Example EI , DI

Disable/enable program of the run of interrupt program by DI and EI.

CJ P20 X000

0

4

5

10 X000

X003

DI

EI

11

CJ P10

Enables execution of interrupt program when X0 is on and disables execution of interrupt program when X0 is off.

P20 P10

••••Coding

0 LD X000

1 CJ P10

4 DI 5 P10

6 LDI X000

7 CJ P20

10 EI 11 P20

12 LD X003

……….

6 − 67 6.5.4 Microcomputer program call

(SUB, SUBP)

The SUB instruction of the AnA, A2AS, AnU, QCPU-A (A Mode) and A2USH board becomes the 16-bit constant setting instruction in the extension application

instructions. For details, refer to the AnSHCPU/AnACPU/AnUCPU Programming Manual (Dedicated Instructions).

Available Device

Bit device Word (16-bit) device Constant Pointer Level Carry flag Error flag

X Y M L S B F T C D W R A0 A1 Z V K H P I N

Digit specification Index

M9012 (M9010, M9011)

n O O O O O O O O O O O O O

Functions (1) Calls the microcomputer program created by user and allows the run of microcomputer program.

(2) When the run of microcomputer program is completed, runs the sequence program again, starting at the next step to the SUB or SUBP instruction.

(3) The SUB and SUBP instructions can be used for the sequence program and subsequence program.

AnS AnN AnSH

An A1FX A3H

A3M A3V AnA

AnU, A2AS

A52G A73 A3N board Applicable

CPU

O O O O O X X O O O O

Remark

n Head address of micro-computer program Setting data

Microcomputer program execution commands

n SUB

n SUBP

Parameter Set value of timer/counter

(4) In the microcomputer program area, multiple microcomputer programs can be created.

(5) For the details of microcomputer program, see Section 8.

Execution The execution conditions of SUB and SUBP instructions are as shown below.

Conditions

Operation Error In the following case, operation error occurs and the error flag turns on.

• An area of more than the microcomputer program capacity has been specified at n.

POINTS

(1) The processing time of a microcomputer program called by one SUB instruction must be 5 msec or less. If it exceeds 5 msec, operation combination between the microcomputer program processing and the internal processing of the PC becomes out of control and the PC cannot run correctly.

(2) If a microcomputer program which needs more than 5 msec for processing is to be executed, divide it into several blocks which are called

consecutively. This method can shorten the processing time of a microcomputer program called by one SUB instruction.

H

SUB 0930

X010

X011

H

SUB 0500

500H Microcomputer program

930H Microcomputer program 0

Head of microcomputer program

OFF

ON

Executed per scan

Executed per scan

Executed only once

Executed only once SUB

SUBP

Microcomputer program execution command

6 − 69 6.6 Program Switching Instructions

6.6.1 Main ↔↔ subprogram switching (CHG)↔↔

Available Device

Bit device Word (16-bit) device Constant Pointer Level Carry flag Error flag

X Y M L S B F T C D W R A0 A1 Z V K H P I N

Digit specification Index

M9012 (M9010, M9011)

Functions (1) Executes switching between the main program and subprogram after the timer/

counter processing and self-diagnostic check, general data processing, data link/network refresh processing, and I/O processing.

(2) For further information on functions and applications, refer to the use of subprograms given in the ACPU Programming Manual (Fundamentals).

POINTS

(1) A4U's CHG instruction is used to switch subsequence programs 1, 2, and 3 which are set in the main sequence program.

When up to subsequence program 2 has been set, programs are switched as the main sequence program

→ subsequence program1 → subsequence program 2

→ main sequence program.

(2) To switch specified programs, use a ZCHG dedicated instruction.

The AnACPU/AnUCPU Programming Manual (Dedicated Instructions)

AnS AnN AnSH

An A1FX A3H

A3M A3V AnA

A2USH-S1 A2USH board

QCPU-A (A Mode)

A0J2H A2C

A52G A73 A3N Applicable boad

CPU

X O O X X O O

Remark *1: A3N only *3: A3A only

*2: A3 only *4: A3U, A4U and Q06H only

Switching command Interlock contact

CHG Timer, counter processing Self-diagnostic check,

general data processing, data link/network refresh processing, and I/O processing.

Sequence program

Sequence program

gives details of the ZCHG instruction.

Execution (1) When the A3 is used, the CHG instruction is only executed on the leading edge Conditions of its input condition. Since operation result of the input condition changes with

status of M9050, execution contents of the CHG instruction change with status of M9050.

Status of M9050

OFF ON

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF No switching between the main and subsequence programs. (4), 5), 11))

No switching between the main and subsequence programs (4), 5), 11))

ON

CHG instruction is executed every scan and switches between the main and subsequence programs.

(2), 3), 7), 8), 9), 10))

The main sequence program is only switched to the subsequence program, then back to the main sequ-ence program on the first leading edge of the CHG instruction execution command (X0). (2))

Operation

Switched between the main and subsequence prog-rams ( 1), 6), 12))

Switched between the main and subsequence prog-rams ( 1), 6), 12))

Remarks When the CHG instruction is executed, END processing (e.g. timer timing, counter counting, WDT reset) is performed for the current program and operation is started from step 0 of the other program.

(2) When the A3N, A73, A3V and A3N board are used, the CHG instruction is only executed on the leading edge of its input condition. Since M9050 is not

provided, execution contents of the CHG instruction are always same.

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF No switching between the main and subsequence programs. (4), 5), 11))

ON The main sequence program is only switched to the subsequence program, then back to the main sequence program on the first leading edge of the CHG instruction execution command (X0). (2))

Operation

Switched between the main and subsequence programs ( 1), 6), 12))

Remarks When the CHG instruction is executed, END processing (e.g. timer timing, counter counting, WDT reset) is performed for the current program and operation is started from step 0 of the other program.

X0

CHG instruction execution in main sequence program execution in main sequence program X000 Inter lock

CHG execution in main sequence program

6 − 71

(3) When the A3H, A3M, AnA, A3U, A4U and Q06H are used, the CHG instruction is executed repeatedly while its input condition is on.

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF No switching between the main and subsequence programs. (4), 5), 11))

ON CHG instruction is executed every scan and switches between the main and subsequence programs. (2), 3), 7), 8), 9), 10))

Operation depending on ON/OFF

of X0 OFF

ON

Switched between the main and subsequence programs (1), 6), 12))

Remarks When the CHG instruction is executed, END processing (e.g. timer timing, counter counting, WDT reset) is performed for the current program and operation is started from step 0 of the other program.

X0

CHG instruction execution in main sequence program

Main sequence program

Subsequence program

CHG instruction execution in subsequence program

OFF ON

1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) X000 Inter lock

CHG

Execution of PLS Instruction Used with CHG Instruction

(1) When the A3 is used, execution contents of the PLS instruction change with status of M9050 when other input conditions are same.

Status of M9050

OFF ON

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF M0 is not switched on. M0 is not switched on.

ON M0 is only switched on during the first scan after switched by the CHG instruction.

M0 is only switched on during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

M0 is only switched on during 1 scan. M0 is only switched on during 1 scan.

(2) When the A3N, A73 and A3V are used, execution contents are always same.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF M0 is not switched on.

ON M0 is only switched on during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

X0

status OFF

ON

M0 is only switched on during 1 scan.

X000

CHG instruction execution CHG instruction execution

1 scan

CHG instruction execution

CHG instruction execution 1scan

CHG instruction execution

OFF

CHG instruction execution

X000

PLS M0 Input condition

0

0

6 − 73

(3) When the A3H, A3M, A3A, A3U, A4U and Q06H are used, the CHG instruction is executed repeatedly while its input condition is on.

Ladder example

The following program is written before END or FEND of the main and subsequence programs.

Timing chart

OFF M0 is not switched on.

ON M0 is only switched on during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

X0 status

OFF

ON

M0 is only switched on during 1 scan.

X000

PLS M0 Input condition

Main sequence program run Subsequence program run

X0

M0

OFF ON

OFF ON

CHG instruction execution

CHG instruction execution 1 scan

0

Execution of P Instruction Used with CHG Instruction

(1) When the A3 is used, execution contents of the PLS instruction change with status of M9050 when other input conditions are same.

Status of M9050

OFF ON

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF MOVP instruction is not executed. MOVP instruction is not executed.

ON The MOVP instruction is executed during the first scan after switched by the CHG instruction.

MOVP instruction is only executed during the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

MOVP instruction is only executed once. MOVP instruction is only executed once.

(2) When the A3N, A73 and A3V are used, execution contents are always same.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF MOVP instruction is not executed.

ON MOVP instruction is only executed duing the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation

MOVP instruction is only executed once.

CHG instruction execution 1 scan

CHG instruction execution

OFF ON

OFF ON

CHG instruction execution 1 scan

CHG instruction execution

CHG instruction execution 1scan

CHG instruction execution MOV

X000 P

X000

MOV 0 D0P K

6 − 75

(3) When the A3H, A3M, A3A, A3U, A4U and Q06H are used, the CHG instruction is executed repeatedly while its input condition is on.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF MOVP instruction is not executed.

ON MOVP instruction is only executed duing the first scan of the subsequence program selected by the CHG instruction executed after X0 is switched on.

Operation depending on X0 ON/OFF

status

OFF

ON

MOVP instruction is only executed once.

CHG instruction execution 1scan

Main sequence program run Subsequence program run

X0

MOVP

OFF ON

OFF ON

CHG instruction execution X000

MOV 0 D0 P K

Counting of Counter Used with CHG Instruction

(1) When the A3 is used, execution contents of the counter change with status of M9050 when other input conditions are same.

Status of M9050

OFF ON

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF C0 count value remains unchanged. C0 cont value remains unchanged.

ON

C0 count value is incremented by 1 after END (FEND, CHG) is executed during the first scan of the program selected by the CHG instruction.

C0 count value is incremented by 1 after END (FEND, CHG) is executed during the first scan of the program selected by the CHG instruction executed after X0 is switched on.

Operation

C0 count value is incremented by 1 after END (FEND, CHG) is executed.

C0 count value is incremented by 1 after END (FEND, CHG) is executed.

(2) When the A3N, A73 and A3V are used, execution contents are always same.

Ladder example

The following program is written at step 0 of the main and subsequence programs.

Timing chart

OFF C0 count value remains unchanged.

ON C0 count value is incremented by 1 after END (FEND, CHG) is executed during the first scan of the program selected by the CHG instruction executed after X0 is switched on.

Operation

C0 count value is incremented by 1 after END (FEND, CHG) is executed.

(3) When the A3H, A3M, A3A, A3U, A4U and Q06H are used, execution contents are always same.

( )

CHG instruction execution

Subsequence program run

X0 OFF

ON

C0 coil OFF ON

C0 count value 0 1 2 3 4

CHG instruction execution

1 scan

Main sequence program run

CHG instruction execution

Subsequence program run

X0 OFF

ON

C0 coil OFF ON

C0 count value 0 1 2

CHG instruction execution

( )

X000 K10

C0

1 scan

CHG instruction execution

Main sequence program run Subsequence program run

CHG instruction execution

X0 OFF

ON

C0 coil OFF

0 1

ON

2

6 − 77 Ladder example

The following program is written at step 0 of the main and subsequence programs.

The following program is written at step 0 of the main and subsequence programs.

相關文件