30.5.8 Inserting Subroutines
Create a new subroutine screen to which the instruction will
jump, and create a subroutine program on the screen.
You can insert JSR instructions anywhere in the logic
program.
When a display unit executes a JSR instruction, the instruction
jumps to the given subroutine with the defined name and the
subroutine is executed.
For example, a subroutine could reset counters every time the
display unit is turned on.
Creating a Subroutine
-
On the toolbar or the [Screen List] window, click
. The [New Screen]
dialog box appears.
-
You can display the [New Screen] dialog box in
either of the following ways.
-
Right-click the logic screen in the [Screen
List] window and select [New Screen (N)].
-
On the [Screen (S)] menu, click [New Screen
(N)].
-
If the [Screen List] tab is not displayed on
the work space, on the [View (V)] menu point to [Work Space (W)]
and then click [Screen List (G)].
-
In [Screens of Type], select [Logic] and in [Logic
Name], select the subroutine name (for example, SUB-01).
Input the title when necessary. You can input up to 30
characters.

-
Click [New]. The subroutine screen will be
displayed.
-
Create the subroutine.
Inserting a JSR Instruction
To execute the subroutine you created in a specific location in
the main logic program [MAIN], you must insert a JSR
instruction.
Here, for example, a subroutine [SUB-01] is executed when the
OUT instruction"Lamp" in the 2nd rung turns on. The JSR instruction
is inserted in the 3rd rung.
-
Select the 2nd rung to enter the rung.

-
Insert a PT instruction in the 3rd rung (Positive
Transition) and assign the symbol variable "Lamp" to the PT
instruction.

-
Insert the JSR instruction to the right of the PT
instruction.

-
For the JSR instruction operand, specify the
[SUB-01] subroutine.
When the "Lamp" ON is detected, the operation jumps to the
subroutine program [SUB-01]. After the subroutine program [SUB-01]
is executed, the main logic program [MAIN] resumes in the 4th rung.

|