Mikroelektronika MIKROE-442 Datenbogen
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
199
Symbols
mikroBasic PRO fordsPIC30/33 and PIC24 symbols allow you to create simple macros without parameters. You can
replace any line of code with a single identifier alias. Symbols, when properly 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 = PORTC ‘ 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.