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

  1. 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)].

  2. 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.

  3. Click [New]. The subroutine screen will be displayed.

  4. 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) on the second rung turns on. The JSR instruction is inserted in the 3rd rung.

  1. Select the second rung to insert a rung.

  2. Insert a PT instruction on the third rung (Positive Transition) and assign the symbol variable (Lamp) to the PT instruction.

     

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

  4. 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 on the fourth rung.