User manual
mikroBasic PRO for PIC32
MikroElektronika
195
sub procedure CircleArea() ‘ Denition 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 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. mikroBasic 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 mikroBasic PRO for PIC32 automatically declares relevant registers as
global variables of word. For example: W0, TMR1, etc.
Constants
Constant is a data whose value cannot be changed during the runtime. Using a constant in a program consumes no
RAM memory. Constants can be used in any expression, but cannot be assigned a new value.
Constants are declared in the declaration part of a program or routine. You can declare any number of constants after
the keyword const:
const constant_name [as type] = value
Every constant is declared under unique constant_name which must be a valid identier. It is a tradition to write
constant names in uppercase. Constant requires you to specify value, which is a literal appropriate for the given type.
type is optional and in the absence of it , the compiler assumes the “smallest” type that can accommodate value.
Note: You cannot omit type when declaring a constant array.
Here are a few examples:
const MAX as longint = 10000
const MIN = 1000 ‘ compiler will assume word type
const SWITCH = “n” ‘ compiler will assume char type
const MSG = “Hello” ‘ compiler will assume string type
const MONTHS as byte[12] = (31,28,31,30,31,30,31,31,30,31,30,31)