English
Language : 

PIC18FXX8 Datasheet, PDF (205/402 Pages) Microchip Technology – 28/40-Pin High-Performance, Enhanced Flash Microcontrollers with CAN Module
PIC18FXX8
EXAMPLE 19-1: WIN AND ICODE BITS USAGE IN INTERRUPT SERVICE ROUTINE TO ACCESS
TX/RX BUFFERS
; Save application required context.
; Poll interrupt flags and determine source of interrupt
; This was found to be CAN interrupt
; TempCANCON and TempCANSTAT are variables defined in Access Bank low
MOVFF CANCON, TempCANCON
; Save CANCON.WIN bits
; This is required to prevent CANCON
; from corrupting CAN buffer access
; in-progress while this interrupt
; occurred
MOVFF CANSTAT, TempCANSTAT
; Save CANSTAT register
; This is required to make sure that
; we use same CANSTAT value rather
; than one changed by another CAN
; interrupt.
MOVF
ANDLW
ADDWF
TempCANSTAT, W
b’00001110’
PCL, F
; Retrieve ICODE bits
; Perform computed GOTO
; to corresponding interrupt cause
BRA
NoInterrupt
BRA
ErrorInterrupt
BRA
TXB2Interrupt
BRA
TXB1Interrupt
BRA
TXB0Interrupt
BRA
RXB1Interrupt
BRA
RXB0Interrupt
; 000 = No interrupt
; 001 = Error interrupt
; 010 = TXB2 interrupt
; 011 = TXB1 interrupt
; 100 = TXB0 interrupt
; 101 = RXB1 interrupt
; 110 = RXB0 interrupt
; 111 = Wake-up on interrupt
WakeupInterrupt
BCF
PIR3, WAKIF
; Clear the interrupt flag
;
; User code to handle wake-up procedure
;
;
; Continue checking for other interrupt source or return from here
…
NoInterrupt
…
; PC should never vector here. User may
; place a trap such as infinite loop or pin/port
; indication to catch this error.
ErrorInterrupt
BCF
PIR3, ERRIF
…
RETFIE
; Clear the interrupt flag
; Handle error.
TXB2Interrupt
BCF
PIR3, TXB2IF
GOTO AccessBuffer
; Clear the interrupt flag
TXB1Interrupt
BCF
PIR3, TXB1IF
GOTO AccessBuffer
; Clear the interrupt flag
TXB0Interrupt
BCF
PIR3, TXB0IF
GOTO AccessBuffer
; Clear the interrupt flag
RXB1Interrupt
BCF
PIR3, RXB1IF
GOTO Accessbuffer
; Clear the interrupt flag
 2004 Microchip Technology Inc.
DS41159D-page 203