User`s manual
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
MikroElektronika:
Development
tools
-
Books
-
Compilers
mikroBASIC
making it simple...
39
page
Variable is data 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 the variable.
Variable can be seen as a container for data and because it is typed, it instructs the
compiler how to interpret the data it holds. For more details refer to Data Types
and Type Conversion.
For more information on variables' scope refer to the chapter Scope (Variable
Visibility).
In mikroBasic, variable needs to be declared before it can be used. Specifying a
data type for each variable is mandatory. Basic syntax for variable declaration is:
dim identifier as type
where identifier is any valid identifier, and type can be any valid data type.
For example:
dim tA as byte
' declare variable tA of byte type
dim tB as word
' declare variable tB of word type
Every declared variable consumes part of MCU RAM memory. Data type of vari-
able determines not only the allowed range of values, but also the space variable
occupies in RAM memory. Bear in mind that operations using different types of
variables take different time to be completed. For example:
Variable tA (byte) occupies 1 byte (8 bit) of RAM memory, while variable tB
(word) occupies 2 bytes (16 bit) of RAM memory.
Therefore, tA = tA + tA is faster to execute than tB = tB + tB.
VARIABLES
Variables
and PIC