User`s guide
MPLAB
®
IDE User’s Guide
DS51519B-page 228 © 2006 Microchip Technology Inc.
bsf TXSTA,BRGH ; Select high baud rate
bsf RCSTA,SPEN ; Enable Serial Port
bsf RCSTA,CREN ; Enable continuous reception
bcf PIR1,RCIF ; Clear RCIF Interrupt Flag
bsf PIE1,RCIE ; Set RCIE Interrupt Enable
bsf INTCON,PEIE ; Enable peripheral interrupts
bsf INTCON,GIE ; Enable global interrupts
;************************************************************
; Main loop
Main
goto Main ; loop to self doing nothing
;************************************************************
; Interrupt Service Routine
IntVector
; save context (WREG and STATUS registers) if needed.
btfss PIR1,RCIF ; Did USART cause interrupt?
goto OtherInt ; No, some other interrupt
movlw 06h ; Mask out unwanted bits
andwf RCSTA,W ; Check for errors
btfss STATUS,Z ; Was either error status bit set?
goto RcvError ; Found error, flag it
movf RCREG,W ; Get input data
movwf LATB ; Display on LEDs
movwf TXREG ; Echo character back
goto ISREnd ; go to end of ISR, restore context, return
RcvError
bcf RCSTA,CREN ; Clear receiver status
bsf RCSTA,CREN
movlw 0FFh ; Light all LEDs
movwf PORTB
goto ISREnd ; go to end of ISR, restore context, return
OtherInt
goto $ ; Find cause of interrupt and service it
; before returning from interrupt. If not,
; the same interrupt will re-occur
; as soon as execution returns to
; the interrupted program.
ISREnd
; Restore context if needed.
retfie
end