User manual
198
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
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)
Labels
Labels serve as targets for goto and gosub statements. Mark the desired statement with label and colon like this:
label_identier : statement
No special declaration of label is necessary in mikroBasic PRO for dsPIC30/33 and PIC24.
Name of the label needs to be a valid identier. The labeled statement and goto/gosub statement must belong to
the same block. Hence it is not possible to jump into or out of routine. Do not mark more than one statement in a block
with the same label.
Note:
- The label main marks the entry point of a program and must be present in the main module of every project. See
Program Organization for more information.
- Label should be followed by end of line (CR) otherwise compiler will report an error.
Here is an example of an innite loop that calls the procedure Beep repeatedly:
loop:
Beep
goto loop