The text of a manual ยท part 32 of 59
Mini-PLC-2/02, 2/16, 2/17 Processor (cat. no. 1772-LZ, LZP, LX, LXP, LW, LWP) User Manual: 17 - Jump Instructions and Subroutines
Pages 260 to 265 of 490, from Mini-PLC-2/02, 2/16, 2/17 Processor (cat. no. 1772-LZ, LZP, LX, LXP, LW, LWP) User Manual
The original document is the PDF (2.4 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Allen-Bradley 1772-LW /LWD, Allen-Bradley 1772-LWP, Allen-Bradley 1772-LX / LXP and Allen-Bradley 1772-LZP
Page 260
Chapter
17
Jump Instructions and Subroutine Programming
Chapter Objectives
This chapter describes the instructions you can use to selectively jump over portions of a program. The instructions are: Jump Jump to Subroutine Label Return This chapter describes how jump instructions and subroutine programming direct the path of the program scan through the main program and the subroutine area.
Jump
A Jump instruction is an output instruction. It has an identification number from 00-07. When its rung is true, it instructs the processor to jump forward in the main program to the Label instruction having the same identification number. The main program executes from that point. 010
01 JMP
00
You can reduce scan time by selectively jumping over a portion of the program. Do not program in an area where the Jump instruction crosses the boundary between the main program and subroutine area, or vice-versa.
ATTENTION: Allowances should be made for conditions which could be created by the Jump instruction. Jumped program rungs are not scanned by the processor. Input conditions are not examined and outputs that are controlled by these rungs remain in their last state. Timers and counters cease to function. Critical rungs should be re-programmed outside of the jumped section in the program.
17-1
Page 261
Chapter 17 Jump Instructions and Subroutine Prorgramming
Jump to Subroutine
The Jump to Subroutine instruction is an output instruction. It has an octal identification number from 00-07. When its rung is true, it instructs the processor to jump from the main program to the label instruction having the same number in the subroutine area. Subroutine execution begins at that point. This instruction always causes the processor to cross the boundary from the main program to the subroutine area. 02
010
JSR 00
Label
The Label instruction is the target for both the Jump and Jump to Subroutine instructions. Label instructions are assigned octal identification numbers from 00-07. The label identification number must be the same as that of the Jump and/or Jump to Subroutine instruction with which it is used. A Label instruction can be defined only once, meaning that a label with a given identification number can only appear in one location. However, a Label instruction can be the target of jumps from more than one location. The Label instruction is always logically true. Programmed as the first condition instruction in the rung. If conditions precede a Label instruction, they will be ignored by the processor during a jump operation. Do not program with a program control instruction. Important: If conditions precede a Label instruction, they are ignored by the processor during a jump operation. 01
010
010
00
00
LBL
ATTENTION: Do not place a Label instruction in a ZCL or MCR zone. When jumping over a start fence, the processor executes the program from the label to the end fence as if the start fence had been true. The start fence may have been false intending that all outputs within the zone are controlled by the output override instruction (i.e. OFF for MCR or last state for ZCL instructions). Failure to observe this warning could cause unexpected operation with possible damage to equipment and/or injury to personnel.
17-2
Page 262
Chapter 17 Jump Instructions and Subroutine Programming
Return
The Return instruction is an output instruction. It is used only in the subroutine area to terminate a subroutine or selectable timed interrupt and return the processor to the main program or, in the case of nested subroutines, return program execution to the preceding subroutine. It returns program execution to the instruction immediately following the Jump to Subroutine instruction that initiated the subroutine. Program execution continues from that point. It is programmed as an output instruction without an identification number in the subroutine area. It is usually programmed unconditionally. Every subroutine must have a Return instruction. RET
Entering Jump Instructions
Enter one of the above instructions by performing the following steps. 1.
Press -(JMP)-, -(SR)-, or [SHIFT] -(RET)-.
Important: Do not perform step 2 for a Return instruction. 2.
Enter <octal identification number>.
Removing a Label Instruction Remove the Label instruction by performing the following steps. 1.
Position the cursor over the Label instruction you want to remove.
2.
Press [Remove][Shift][LBL].
Editing Jump Instructions Edit one of the above instructions by performing the following steps. 1.
Position the cursor over the instruction you are going to edit.
2.
Press [Remove]
3.
Press -(JMP)-, -(JSR)-, or [SHIFT]-(RET)- or any other appropriate instruction type key.
Important: Do not perform step 3 for a Return instruction. 4.
Subroutine Area Instruction
Enter <octal identification number>.
The subroutine area is located in the memory between the end of the main program and the beginning of the message store areas (Figure 17.1). The subroutine area allows you to store small programs you plan to access periodically. Subroutines are not scanned unless you program the processor to jump into this area.
17-3
Page 263
Chapter 17 Jump Instructions and Subroutine Prorgramming
Figure 17.1 Subroutine Area Total Decimal Words
Timer Counter Preset Values (PR) (or Bit Word Storage)
Varies
Octal Word Address
Data Table 177 200
Main Program
Varies
Subroutine Area
Varies
User Program
Subroutines
Varies
End
Varies
Message Storage Area (if used)
17-4
Mini-PLC-2/02 Mini-PLC-2/16 Mini-PLC-2/17
1920 3968 7808
Mini-PLC-2/02 Mini-PLC-2/16 Mini-PLC-2/17
2048 4096 7936
User Program
Message Storage 3577 7577 17177
Mini-PLC-2/02 Mini-PLC-2/16 Mini-PLC-2/17
3777 7777 17377
Mini-PLC-2/02 Mini-PLC-2/16 Mini-PLC-2/17
Page 264
Chapter 17 Jump Instructions and Subroutine Programming
You can program a maximum of 8 subroutines in the subroutine area. Each subroutine begins with a Label instruction and ends with a return instruction. The Return should be an unconditional rung. The subroutine area serves as the end of the main program and defines the beginning of the subroutine area (Figure 17.2). Figure 17.2 Subroutine Programming Example 01 JSR
112 00 112
013 10 012 U OFF 11 200 U OFF 17
02 114 06 116 02 116 02 116 13 SUBROUTINE AREA 01 LBL
114
012
06
11
116
116
116
FILE TO FILE MOVE
11
12
13
COUNTER ADDR: 200 POSITION: 001 FILE LENGTH: 007 FILE A: 400- 406 FILE R: 500- 506 RATE PER SCAN: 007
200 EN
17
200 DN 15 RET
You can establish a subroutine area by performing the following steps. 1. Move the cursor down to the end of the main program. 2. Press [Shift] [SBR]
17-5
Page 265
Chapter 17 Jump Instructions and Subroutine Prorgramming
The boundary marker subroutine area appears. A Subroutine Area instruction can only be programmed after the last instruction in the main program. The Subroutine Area instruction cannot be inserted between rungs in the main program. It requires 1 word of memory, it can be programmed only once, and it cannot be removed except by clearing the memory. You cannot nest subroutine programs by inserting a Jump To Subroutine instruction within the subroutine area, but it is possible to jump from one subroutine to another using a Jump instruction.
17-6