English
Language : 

PIC18F2585_07 Datasheet, PDF (280/482 Pages) Microchip Technology – Enhanced Flash Microcontrollers with ECAN Technology, 10-Bit A/D and nanoWatt Technology
PIC18F2585/2680/4585/4680
EXAMPLE 23-1: CHANGING TO CONFIGURATION MODE
; Request Configuration mode.
MOVLW B’10000000’
; Set to Configuration Mode.
MOVWF CANCON
; A request to switch to Configuration mode may not be immediately honored.
; Module will wait for CAN bus to be idle before switching to Configuration Mode.
; Request for other modes such as Loopback, Disable etc. may be honored immediately.
; It is always good practice to wait and verify before continuing.
ConfigWait:
MOVF CANSTAT, W
; Read current mode state.
ANDLW B’10000000’
; Interested in OPMODE bits only.
TSTFSZ WREG
; Is it Configuration mode yet?
BRA
ConfigWait
; No. Continue to wait...
; Module is in Configuration mode now.
; Modify configuration registers as required.
; Switch back to Normal mode to be able to communicate.
EXAMPLE 23-2: 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 TempCANSTAT, W
; Retrieve ICODE bits
ANDLW B’00001110’
ADDWF PCL, F
; Perform computed GOTO
; to corresponding interrupt cause
BRA
NoInterrupt
; 000 = No interrupt
BRA
ErrorInterrupt
; 001 = Error interrupt
BRA
TXB2Interrupt
; 010 = TXB2 interrupt
BRA
TXB1Interrupt
; 011 = TXB1 interrupt
BRA
TXB0Interrupt
; 100 = TXB0 interrupt
BRA
RXB1Interrupt
; 101 = RXB1 interrupt
BRA
RXB0Interrupt
; 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.
DS39625C-page 278
Preliminary
© 2007 Microchip Technology Inc.