;------------------------------------------------------------------------------- ;----------------- Asynchronous Serial Receive Initialisation ----------------- ;------------------------------------------------------------------------------- serialinit bsf STATUS, RP0 ; Set RP0 to 1 ; Bank 1 Selected bsf TRISB, 1 ; Both serial input and output must bsf TRISB, 2 ; be set as inputs. bsf TXSTA, BRGH ; Set high baud rate movlw d'129' movwf SPBRG ; Set baud rate to 9600 bcf TXSTA, SYNC ; Set to asynchronous mode bcf STATUS, RP0 ; Set RP0 to 0 ; Bank 0 Selected bsf INTCON, PEIE ; Turn on peripheral interrupts bsf RCSTA, SPEN ; Enable Serial Port bsf STATUS, RP0 ; Set RP0 to 1 ; Bank 1 Selected bsf PIE1, RCIE ; Turn on Serial Receive Interrupt bcf STATUS, RP0 ; Set RP0 to 0 ; Bank 0 Selected bsf RCSTA, CREN ; Turns on receive movf RCREG, w movf RCREG, w movf RCREG, w ; Clear contents to clear interrupt bsf INTCON, GIE ; Enable interrupts ;------------------------------------------------------------------------------- ;---------------------------- Interrupt Program ------------------------------ ;------------------------------------------------------------------------------- Interrupt movwf w_save movf STATUS, w clrf STATUS movwf status_save movf RCREG, w movwf sertemp ; For example this line could set an ; action in motion such as save to movf status_save, w ; EEPROM or write to LCD. movwf STATUS swapf w_save, f swapf w_save, w retfie