Add New Subroutine |
Topic: CL070
|
Subroutines can be created to isolate a body of code that is run selectively from the Main Program using the Call instruction. Subroutine Programs are created and named using the New Subroutine Program dialog, which is accessed from the Program Menu,by using the Ctrl + U keyboard shortcut, or by right-clicking on an existing subroutine in the Navigation Panel. You can have up to 986 Subroutine Programs in a CLICK project. To insert the Call instruction into the ladder program, a Subroutine Program must be created. Even if you only create a named Subroutine Program with a blank ladder, this will provide the Name of the Subroutine Program so the Call instruction can be inserted into the ladder program. (See below)
Create a Subroutine Program using this dialog. The name can be a maximum of 24 characters long. Click OK to create the Subroutine Program and open the Ladder Editor to the new program.
Before the Subroutine Program opens, first time users of CLICK Subroutines will encounter the Quick Guide for Subroutines, which contains important information about Subroutines.
A Subroutine Program must have at least one Return instruction to go back to the Main Program.
If a Subroutine Program is not called during the execution of a Program, the Memory Addresses used in the Subroutine Program maintain their previous state.
It is not allowed to nest one Subroutine inside another Subroutine. Subroutines must be called from the Main Program.
The END instruction cannot appear in a Subroutine. An END instruction is required in the Main Program.
|
Note: The background color of the Subroutine Program is different from the Main Program or Interrupt Programs to alert the programmer that the Subroutine Program is the active program. To customize the colors of the Ladder Editor, look at Software Setup Color. |
To View Subroutine Programs
The Subroutine Program just created or any existing Subroutine Program can be viewed by clicking on the Subroutine Program selection of the Program Tree located on the left panel of the screen as shown below. When selected, the tree will expand and display any existing Subroutine Programs.
To return to the Main Program, use the Window Menu and select Main Program. Also visit the Window Menu to Tile or CascadeProgram Windows.
If a Subroutine has not been created, the Call instruction cannot be placed in the ladder program. This message will appear.