Mikroelektronika MIKROE-724 データシート
196
mikoBasic 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 identifier. This name is used for accessing the memory location occupied by a variable.
Variables are declared in the declaration part of the file 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
include
statements,
above the label
main
.
Specifying a data type for each variable is mandatory. Syntax for variable declaration is:
dim identifier_list as type
Here,
identifier_list
is a comma-delimited list of valid identifiers, 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.
Here are a few examples:
dim i, j, k as byte
dim counter, temp as word
dim samples as longint[100]
External Modifier
Use the
external
modifier to indicate that the actual place and initial value of the variable, sub function or sub
procedure body, is defined in a separate source code module.
For example, lets create a project which will calculate circle area and will have sub function and sub procedure definition
in two different modules, and a call to these routines in the third, separate module.
So, the project will be consisted of the main module,
Main_Module.mpas
and
First_Module.mpas
and
Second_
Module.mpas
modules.
In the
Main_Module
we will define routine called
r_squared
(calculates radius squared). Also, both modules must
be included in the
Main_Module
:
program Main_Module
include First_Module
include Second_Module ‘ Include both used modules
sub function r_square(dim r as float) as float ‘ Definition of the r_square routine
result = r*r;
end sub
main:
CircleArea() ‘ CircleArea routine call
end.
end.