Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
; This part of the program is executed in interrupt routine
banksel PIE1
btfss PIE1, RCIE
goto ISR_Not_RX232int
banksel PIE1
btfsc PIR1, RCIF
call RX232_int_proc
ISR_Not_RX232int
movf pclath_temp,w
movwf PCLATH ; PCLATH is given its original value
movf status_temp,w
movwf STATUS ; STATUS is given its original value
swapf w_temp,f
swapf w_temp,w ; W is given its original value
retfie ; Return from interrupt routine
;**********************************************************************
RX232_int_proc ; Check if error has occurred
banksel RCSTA
movf RCSTA, w
movwf RS232temp
btfsc RS232temp, FERR
goto RX232_int_proc_FERR
btfsc RS232temp, OERR
goto RX232_int_proc_OERR
goto RX232_int_proc_Cont
RX232_int_proc_FERR
bcf RCSTA, CREN ; To clear FERR bit, receiver is first
; switched off and on afterwards
nop ; Delay ...
nop
bsf RCSTA, CREN
movf RCREG, w ; Reads receive register and clears FERR bit
bsf Port_A, 0 ; Switches LED on ( UART error indicator)
movf Port_A, w
movwf PORTA
goto RS232_exit
RX232_int_proc_OERR
bcf RCSTA, CREN ; Clears OERR bit
nop ; Delay ...
nop
bsf RCSTA, CREN
movf RCREG, w ; Reads receive register and clears FERR bit
bsf Port_A, 1 ; Switches LED on ( UART error indicator)
movf Port_A, w
movwf PORTA
goto RS232_exit
RX232_int_proc_Cont
movf RCREG, W ; Reads received data
movwf RXchr
movwf PORTB
movwf TXREG ; Sends data back to PC
RS232_exit
return ; Return from interrupt routine
;**********************************************************************
; Main program
main
banksel ANSEL ; Selects bank containing ANSEL
clrf ANSEL ; All inputs are digital
clrf ANSELH
;---------------------------------------
; Port configuration
;---------------------------------------
banksel TRISA
movlw b'11111100'
http://www.mikroe.com/en/books/picmcubook/appb/ (53 of 54)5/3/2009 11:36:02 AM