PIC18F2480/2580/4480/4580
EXAMPLE 24-2:
WIN AND ICODE BITS USAGE IN INTERRUPT SERVICE ROUTINE TO ACCESS
TX/RX BUFFERS (CONTINUED)
ErrorInterrupt
BCF
…
PIR3, ERRIF
; Clear the interrupt flag
; Handle error.
RETFIE
TXB2Interrupt
BCF
GOTO
TXB1Interrupt
BCF
GOTO
TXB0Interrupt
BCF
GOTO
RXB1Interrupt
PIR3, TXB2IF
AccessBuffer
; Clear the interrupt flag
; Clear the interrupt flag
; Clear the interrupt flag
; Clear the interrupt flag
PIR3, TXB1IF
AccessBuffer
PIR3, TXB0IF
AccessBuffer
BCF
GOTO
PIR3, RXB1IF
Accessbuffer
RXB0Interrupt
BCF
GOTO
PIR3, RXB0IF
AccessBuffer
; Clear the interrupt flag
AccessBuffer
; This is either TX or RX interrupt
; Copy CANSTAT.ICODE bits to CANCON.WIN bits
MOVF
TempCANCON, W
; Clear CANCON.WIN bits before copying
; new ones.
ANDLW
B’11110001’
; Use previously saved CANCON value to
; make sure same value.
MOVWF
MOVF
ANDLW
TempCANCON
TempCANSTAT, W
B’00001110’
; Copy masked value back to TempCANCON
; Retrieve ICODE bits
; Use previously saved CANSTAT value
; to make sure same value.
IORWF
MOVFF
TempCANCON
TempCANCON, CANCON
; Copy ICODE bits to WIN bits.
; Copy the result to actual CANCON
; Access current buffer…
; User code
; Restore CANCON.WIN bits
MOVF
ANDLW
IORWF
CANCON, W
B’11110001’
TempCANCON
; Preserve current non WIN bits
; Restore original WIN bits
; Do not need to restore CANSTAT - it is read-only register.
; Return from interrupt or check for another module interrupt source
© 2009 Microchip Technology Inc.
DS39637D-page 285