Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
#IFDEF flag THEN
block of code
[ #ELSEIF flag_1 THEN
block of code 1
...
#ELSEIF flag_n THEN
block of code n ]
[ #ELSE
alternate block of code ]
#ENDIF
First, 
#IFDEF
checks if flag is set by means of 
#DEFINE
. If so, only block of code will
be compiled. Otherwise, the compiler will check flags 
flag_1 .. flag_n
and exe-
cute the appropriate block of code i. Eventually, if none of the flags is set, alternate
block of code in 
#ELSE
(if any) will be compiled.
#ENDIF
ends the conditional sequence. The result of the preceding scenario is that
only one section of code (possibly empty) is passed on for further processing. The
processed section can contain further conditional clauses, nested to any depth;
each 
#IFDEF
must be matched with a closing 
#ENDIF
.
Here is an example:
' Uncomment the appropriate flag for your application:
'#DEFINE resolution8
'#DEFINE resolution10
'#DEFINE resolution12
#IFDEF resolution8 THEN
... ' code specific to 8-bit resolution
#ELSEIF resolution10 THEN
... ' code specific to 10-bit resolution
#ELSEIF resolution12 THEN
... ' code specific to 12-bit resolution
#ELSE
... ' default code
#ENDIF
Predefined Flags
The compiler sets directives upon completion of project settings, so the user does-
n't need to define certain flags.
Here is an example:
#IFDEF ATMEGA16 ' If ATmega16 MCU is selected
#IFDEF ATMEGA128 ' If ATmega128 MCU is selected
In some future releases of the compiler, the JTAG flag will be added also.
See also predefined project level defines.
165
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5