You always want to clear interrupt flag bits before re-enabling interrupts.
RCIF is the serial receive interrupt flag.
Since RCIF is read-only, you need to read RCREG until it's empty to clear
RCIF. You'll also want to clear any over-run conditions.
Code:
OERR VAR RCSTA.1 ' Alias USART over-run bit
CREN VAR RCSTA.4 ' Alias USART continuous receive enable bit
RCIF VAR PIR1.5 ' Alias USART received character interrupt flag bit
Try adding this to your BASIC interrupt routine.
Code:
DISABLE
indirizzo:
PORTB.7 = PORTB.7 ^ 1 ' Toggle LED on entry to int handler
IF OERR = 1 THEN ' If over-run, then clear it
CREN = 0 ' Disable receive
CREN = 1 ' Re-enable & clear over-run condition
ENDIF
WHILE RCIF ' If RCIF is set, then read RCREG until it's clear
X = RCREG
WEND
RESUME
ENABLE
Bookmarks