Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
SYMBOLS
mikroBasic PRO symbols allow you to create simple macros without parameters.
You can replace any line of code with a single identifier alias. Symbols, when prop-
erly used, can increase code legibility and reusability.
Symbols need to be declared at the very beginning of the module, right after the
module name and (optional) 
include
clauses. Check Program Organization for
more details. Scope of a symbol is always limited to the file in which it has been
declared.
Symbol is declared as:
symbol alias = code
Here, 
alias
must be a valid identifier which you will use throughout the code. This
identifier has a file scope. The 
code
can be any line of code (literals, assignments,
function calls, etc).
Using a symbol in the program consumes no RAM – the compiler will simply replace
each instance of a symbol with the appropriate line of code from the declaration.
Here is an example:
symbol MAXALLOWED = 216     
' Symbol as alias for numeric value
symbol PORT = P0           
' Symbol as alias for SFR
symbol MYDELAY = Delay_ms(1000)  
' Symbol as alias for procedure call
dim cnt as byte
' Some variable
'...
main:
if cnt > MAXALLOWED then
cnt = 0
PORT.1 = 0
MYDELAY
end if
Note: Symbols do not support macro expansion in a way the C preprocessor does.
130
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5