list p=p16f628a
#include "p16f628a.inc"
; configurations
;__config _WDT_OFF & _INTOSC_OSC_NOCLKOUT
__config _WDT_OFF & _HS_OSC
; constants
MATCH_STR_LEN equ 7 ; length of the match string
FIX_IND_PIN equ 0 ; fix indicator output pin on port B
; some labels for blocks of memory
cblock 0x20
CUR_MATCH_P: 1 ; pointer to the current character of match
; string
MATCH_STR: MATCH_STR_LEN ; match string - e.g. $GCDSS
IN_BUFFER_LEN: 1 ; length of the input buffer
IN_BUFFER: 40 ; start of the input buffer
REC_TMP: 1 ; temporary location to store received byte
endc
; file intializers
clrf IN_BUFFER_LEN
clrf CUR_MATCH_P
movlw "$"
movwf MATCH_STR
movlw "G"
movwf MATCH_STR + 1
movlw "P"
movwf MATCH_STR + 2
movlw "G"
movwf MATCH_STR + 3
movlw "G"
movwf MATCH_STR + 4
movlw "A"
movwf MATCH_STR + 5
movlw ","
movwf MATCH_STR + 6
; uart initialization
bsf STATUS, RP0 ; switch to bank 1
; set up UART receive interrupt
;bsf INTCON, GIE
;bsf INTCON, PEIE
;bsf PIE1, RCIE
;bcf INTCON, INTF
; set up the receiver
bcf STATUS, RP0 ; switch to bank 0
bsf RCSTA, SPEN
bsf RCSTA, CREN
; set up RB1 and RB2 as input ports to allow
; UART module to use them for send/receive
bsf STATUS, RP0 ; switch to bank 1
bsf TRISB, 1 ; UART receive pin
bsf TRISB, 2 ; UART transmit pin
bcf TRISB, FIX_IND_PIN ; GPS fix indicator pin (output)
; set up the transmitter
movlw 32 ; this should give us ~38K baud (37878 according to datasheet)
movwf SPBRG
bsf TXSTA, BRGH
bsf TXSTA, TXEN
bcf TXSTA, SYNC
bcf STATUS, RP0 ; switch back to bank 0
bcf PORTB, FIX_IND_PIN ; by default, the fix indicator pin is low
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; main program loop which waits for an incoming
; NMEA 0183 sentence
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LOOP:
btfss PIR1, RCIF
goto LOOP
movf RCREG, W ; read the character from buffer
; any errors
btfsc RCSTA, OERR
goto CLEAR_ERROR
btfsc RCSTA, FERR
goto FRAMING_ERROR
TXLOOP:
btfss PIR1, TXIF
goto TXLOOP
movwf TXREG
goto LOOP
FRAMING_ERROR:
bsf PORTB, FIX_IND_PIN
goto LOOP
CLEAR_ERROR:
bcf RCSTA, CREN
bsf RCSTA, CREN
goto LOOP
end