Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
197
In the 
First_Module
 we will define 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 float)  ‘ Declaration of the pi_r_square routine
implements
sub procedure pi_r_square(dim rr as float)  ‘ Definition of the pi_r_square routine
  dim res as float
  res = rr*3.14
end sub
end.
In the 
Second_Module
 we will make a call to the routines defined externally (
r_squared 
and
 pi_r_squared
). First 
of all, we must declare their prototypes followed with a 
external
 modifier. Then, we can proceed to the routine call :
module Second_Module
sub procedure CircleArea()
sub function r_square(dim r as float) as float external  ‘ Declaration of the r_square 
routine (defined in Main_Module) followed with a external modifier
sub procedure pi_r_square(dim rr as floatexternal      ‘ Declaration of the pi_r_square 
routine (defined in Second_Module) followed with a external modifier
implements
sub procedure CircleArea()  ‘ Definition 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.