User manual

196
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Variables
Variable is an object whose value can be changed during the runtime. Every variable is declared under unique name
which must be a valid identier. This name is used for accessing the memory location occupied by a variable.
Variables are declared in the declaration part of the le or routine — each variable needs to be declared before being
used. Global variables (those that do not belong to any enclosing block) are declared below the uses statement, above
the keyword begin.
Specifying a data type for each variable is mandatory. Syntax for variable declaration is:
var identier_list : type;
Here, identier_list is a comma-delimited list of valid identiers, and type can be any data type.
For more details refer to Types and Types Conversions. For more information on variables’ scope refer to the chapter
Scope and Visibility.
Pascal allows shortened syntax with only one keyword var followed by multiple variable declarations. For example:
var i, j, k : byte;
counter, temp : word;
samples : array[100] of word;
External Modier
Use the external modier to indicate that the actual place and initial value of the variable, function or procedure body,
is dened in a separate source code unit.
For example, lets create a project which will calculate circle area and will have function and procedure denition in two
different units, and a call to these routines in the third, separate unit.
So, the project will be consisted of the main unit, Main_Unit.mpas and First_Unit.mpas and Second_Unit.
mpas units.
In the Main_Unit we will dene routine called r_squared (calculates radius squared). Also, both units must be
included in the Main_Unit:
program Main_Unit;
uses First_Unit, Second_Unit; // Include both used units
function r_squared(r : real) : real; // Denition of the r_squared routine
begin
result := r*r;
end;
begin
CircleArea(); // CircleArea routine call
end.