AKD BASIC User Guide | 3 AKDBASICLanguage
'-------------- Subroutines and Functions -----
-------
function cube(i as integer) as integer
cube = i * i * i
end function
sub increment
i = i + 1
end sub
This program prints a table of the cubes of the integers from 1 to 10. The first (global) definition
of ‘i’ is visible inside subroutine ‘increment’, but ‘shadowed’ by the ‘i’ in main and function
‘cube’. The definition of ‘i’ inside ‘main’ is local to ‘main’, and is NOT the same variable as the ‘i’
inside the function ‘cube’, or inside the subroutine ‘increment’. These same scope rules apply to
constant definitions and aliases, as well.
3.2 Program Sections
The major sections of an AKD BASIC program are:
l setup parameter definitions
l global variables, constants, and aliases
l ‘main’ program, subroutines, functions, and interrupt handlers
Although these sections may appear in any order, we recommend that you keep them in the
order shown, or at least, choose a single layout style and use it consistently.
3.2.1 Program Template
The program below is an example of the template generated automatically by WorkBench:
'-------------- Device Params -----------------
------
Params
End Params
'-------------- Define (dim) Global Variables -
-------
'-------------- Main Program ------------------
-------
Main
End Main
'-------------- Subroutines and Functions ----
--------
'-------------- Interrupt Routines -----------
--------
These sections are described in greater detail in the following paragraphs.
3.2.2 Setup Parameter Definitions
This section of the program defines the setup parameters for drive tuning and configuration. It is
executed immediately upon power-up (if VM.AUTOSTART = 1), before entering main, and
before any interrupts are enabled. The section begins with Param and ends with End Param
21 Kollmorgenâ„¢ | March 30, 2012