User manual

194
mikoPascal PRO for PIC32
MikroElektronika
In the First_Unit we will dene and declare routine called pi_r_squared (calculates pi multiplied by the radius
squared):
unit First_Unit;
procedure pi_r_squared(rr : real); // Declaration of the pi_r_squared routine
implementation
procedure pi_r_squared(rr : real); // Denition of the pi_r_squared routine
var res : real;
begin
res := rr*3.14;
end;
end.
In the Second_Unit 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 :
unit Second_Unit;
procedure CircleArea();
function r_squared(r : real) : real; external; // Declaration of the r_squared routine
(dened in Main_Unit) followed with a external modier
procedure pi_r_squared(rr : real); external; // Declaration of the pi_r_squared
routine (dened in First_Unit) followed with a external modier
implementation
procedure CircleArea(); // Denition of the CircleArea routine
var res : real;
begin
res := r_squared(5); // r_squared routine call
pi_r_squared(res); // pi_r_squared routine call
end;
end.
Variables and PIC32
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. mikroPascal PRO for PIC32 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 mikroPascal PRO for PIC32 automatically declares relevant registers
as global variables of volatile word see SFR for details.