User manual

194
mikoBasic PRO for PIC32
MikroElektronika
For example, lets create a project which will calculate circle area and will have sub function and sub procedure denition
in two different modules, and a call to these routines in the third, separate module.
So, the project will be consisted of the main module, Main_Module.mpas and First_Module.mpas and Second_
Module.mpas modules.
In the Main_Module we will dene routine called r_squared (calculates radius squared). Also, both modules must
be included in the Main_Module:
program Main_Module
include First_Module
include Second_Module ‘ Include both used modules
sub function r_square(dim r as oat) as oatDenition of the r_square routine
result = r*r;
end sub
main:
CircleArea() ‘ CircleArea routine call
end.
end.
In the First_Module we will dene and declare routine called pi_r_squared (calculates pi multiplied by the radius
squared):
module First_Module
sub procedure pi_r_square(dim rr as oat) ‘ Declaration of the pi_r_square routine
implements
sub procedure pi_r_square(dim rr as oat) ‘ Denition of the pi_r_square routine
dim res as oat
res = rr*3.14
end sub
end.
In the Second_Module we will make a call to the routines dened externally (r_squared and pi_r_squared). First
of all, we must declare their prototypes followed with a external modier. Then, we can proceed to the routine call:
module Second_Module
sub procedure CircleArea()
sub function r_square(dim r as oat) as oat external Declaration of the r_square
routine (dened in Main_Module) followed with a external modier
sub procedure pi_r_square(dim rr as oat) external Declaration of the pi_r_square
routine (dened in Second_Module) followed with a external modier
implements