User manual

mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
197
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
sub procedure CircleArea() ‘ Denition of the CircleArea routine
dim res as real
res = r_square(5) ‘ Calculate r*r
pi_r_square(res) ‘ Calculate pi*r*r
end sub
end.
Variables and dsPIC30/33 and PIC24
Every declared variable consumes part of RAM memory. Data type of variable determines not only the allowed range
of values, but also the space a variable occupies in RAM memory. Bear in mind that operations using different types
of variables take different time to be completed. mikroBasic PRO for dsPIC30/33 and PIC24 recycles local variable
memory space local variables declared in different functions and procedures share the same memory space, if
possible.
There is no need to declare SFRs explicitly, as mikroBasic PRO for dsPIC30/33 and PIC24 automatically declares
relevant registers as global variables of word. For example: W0, TMR1, etc.