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 identier. 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 identier_list : type;
Here, identier_list is a comma-delimited list of valid identiers, 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 Modier
Use the external modier to indicate that the actual place and initial value of the variable, function or procedure body,
is dened in a separate source code unit.
For example, lets create a project which will calculate circle area and will have function and procedure denition 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 dene 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; // Denition of the r_squared routine
begin
result := r*r;
end;
begin
CircleArea(); // CircleArea routine call
end.