PICkit™ 3 Starter Kit User’s Guide
DS41628B-page 78 2012 Microchip Technology Inc.
EXAMPLE 3-40:
The #ifdef is a preprocessor directive, which will look to see if the directive, in this
case PULL_UPS, is defined. If so, the code between the #ifdef and #endif will be
assembled. These two lines activate the weak pull-up resistor on pin RA2.
3.11.6.3 PIC18
The PIC18 does not differentiate between rising and falling edges. Therefore, the same
debounce routine and flowchart in Lesson 7 (Figure 3-6) will be used.
EXAMPLE 3-41:
When priority interrupts are disabled, all interrupts occur at address 0x0008.
EXAMPLE 3-42:
Same as the PIC16, except that the registers and bit names are changed slightly.
3.11.7 C Language
The enhanced core can have only one interrupt vector defined. This is done by creating
a function with the interrupt keyword:
void interrupt ISR(void)
This is a special name and is reserved only for the ISR. The PIC18 can have two, but
this lesson uses only one as shown above.
#ifdef PULL_UPS
banksel WPUA
bsf WPUA, 2 ;enable the weak pull-up for the switch
banksel OPTION_REG
bcf OPTION_REG, NOT_WPUEN ;enable the global weak pull-up bit
;this bit is active HIGH, meaning it must be cleared for it to be enabled
#endif
Org 0x0000 ;Reset Vector starts at 0x0000
bra Start ;main code execution
Org 0x0008 ;High Priority Interrupt Vector starts at address 0x0008
goto ISR
#ifdef PULL_UPS
bsf WPUA, 2 ;enable the weak pull-up for the switch
bcf INTCON2, NOT_RABPU ;enable the global weak pull-up bit
;this bit is active HIGH, meaning it must be cleared for it to be enabled
#endif