Mikroelektronika MIKROE-350 Data Sheet

Page of 526
VARIABLES
Variable is an object whose value can be changed during the runtime. Every vari-
able is declared under unique name which must be a valid identifier. This name is
used for accessing the memory location occupied by the variable.
Variables are declared in the declaration part of the file or routine — each variable needs
to be declared before it is used. Global variables (those that do not belong to any enclos-
ing block) are declared below the 
include
statements, above the label 
main
.
Specifying a data type for each variable is mandatory. mikroBasic PRO 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]
Variables and AVR
Every declared variable consumes part of RAM memory. Data type of variable deter-
mines 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 AVR 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 SFR explicitly, as mikroBasic PRO for AVR automatically
declares relevant registers as global variables of 
word
. For example: 
W0
TMR1
, etc.
127
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5