Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix A: Programming a Microcontroller
RIGHT ; address 0x24
ENDC
...
IF, ENDIF and ELSE directives
These directives are used to create so called conditional blocks in a program. Each of these blocks starts with the directive
IF and ends with the directive ENDIF or ELSE. A statement or a symbol (in parentheses) following the directive IF
represents a condition which determines which part of the program is to be compiled:
● If the statement is correct or the value of a symbol is equal to one, program compiles all instructions written before
directive ELSE or ENDIF; and
● If the statement is not correct or the value of a symbol is equal to zero, only instructions written after directives
ELSE or ENDIF are to be compiled.
Example 1:
IF (VERSION>3)
CALL Table_2
CALL
ENDIF
...
If the program is released after the version 3 (statement is right) then subroutines "Table 2" and "Extension" are executed.
If the statement in parentheses is wrong (VERSION<3), two instructions calling subroutines are ignored and will not be
compiled therefore.
Example 2:
If the value of symbol "Model" is equal to one then first two instructions after directive IF are compiled as well as
instructions after directive ENDIF (all instructions between ELSE and ENDIF are ignored). Otherwise, if Model=0 then
instructions between IF and ELSE are ignored, whereas instructions after directive ELSE are compiled.
IF (Model)
MOVFW BUFFER
MOVWF MAXIMUM
ELSE
MOVFW BUFFER1
MOVWF MAXIMUM
ENDIF
...
BANKSEL directive
In order to access an SFR register it is necessary to select the appropriate bank in RAM memory by using bits RP0 and RP1
of the STATUS register. This directive is used in this case. Simply, since "inc" data file contains the list of all registers along
with their addresses, the assembler knows which bank corresponds to which register. After encountering this directive,
assembler selects the bits RP0 and RP1 for the specified register on its own. For example:
...
BANKSEL TRISB
CLRF TRISB
MOVLW B’01001101’
BANKSEL PORTB
MOVWF PORTB
...
http://www.mikroe.com/en/books/picmcubook/appa/ (5 of 21)5/3/2009 11:35:35 AM