truebit
Newbie
Offline
Posts: 7
Thank You
-Given: 4
-Receive: 1
|
 |
« Reply #4 on: December 13, 2007, 12:10:12 00:10 » |
|
Hi, This is part of the code I used to read the binary data from a motorola Oncore gps timing RX (they do/did a version that can output 10Khz as well). You can switch between binary and nema mode. I have not included the LCD routine as that is prety standard. Hope it might be of help.
; Code to read Oncore Data stream
GetRx call readst ; read receiver data string iorlw 0 ; test W, 0 = checksum good btfss status,z ; if read error do not update lcd return ; Call again for second string call readst ; read receiver data string iorlw 0 ; test W, 0 = checksum good btfss status,z return ; if read error do not update lcd MOVLW 0x01 ; Clear LCD CALL cout CALL chkbsy
movf day,w ;Send date call p_bin movlw '-' call dout movf month,w call p_bin movlw '-' call dout movf year_hb,w movwf hbyte movf year_lb,w movwf lbyte call bin2bcd call p_4 ; send 4 lsd from "R" reg to LCD
movlw ' ' ; send space call dout
movf hour,w ; send time call p_bin movlw ':' call dout movf min,w call p_bin movlw ':' call dout movf sec,w call p_bin movlw 0xA8 ; move cursor to start of Line 2 call cout
movlw AntO-msg1 ; open msg btfsc ant,7 ;if set antenna = open goto gopn btfss ant,6 ;if set antenna = short goto agood movlw AntS-msg1 ; short msg gopn call p_msg ; send msg movlw 0x01 movwf holdflg ; if antenna faulty enter holdover mode return ; and exit
agood movlw Sats-msg1 ; else print number of sats tracked call p_msg movf track,w call p_hex movlw ' ' call dout ; and lock status
incf mode,w ;get current mode +1 sublw lockval ;mode number for lock light to be on btfsc status,c goto grx1 ; not locked
movf Erstat,f ;Traim status btfss status,z ; 0 = good goto grx3 ; hold clrf holdflg ; clear hold flag movlw Lok-msg1 goto p_msg grx1 clrf holdflg movlw Aqu-msg1 goto p_msg
grx3 movf holdflg,f ;if holdflg is 0 then set it to 1 btfsc status,z ;if not zero then leave as is incf holdflg,f ;as flag is incremented by Int service movlw hold-msg1 ;every Ts call p_msg movlw ' ' ;send space call dout clrc rrf holdflg,w ;get hold count divided by 2 goto p_bin ;send to LCD
Wait@@ call sbyte sublw '@' ;is it ascii @ btfss status,z goto wait@@ call sbyte sublw '@' ;is it ascii @ btfss status,z goto wait@@ clrf cksum ;checksum all bytes after the @@ start return
readst call wait@@ call sbyte sublw 'E' ;is it ascii E btfss status,z goto readst call sbyte sublw 'a' ;is it ascii a btfsc status,z goto EaString movf SerialData,w ;get back data byte sublw 'n' ;is it ascii n btfsc status,z goto EnString goto readst ;not what we want so keep looking
EnString ;Traim data string
movlw D'17' ;skip first 17 bytes call skipn call sbyte movwf Erstat
movlw D'3' ;skip next 3 bytes call skipn
call sbyte movwf nsecerr ;nanoseconds error +-128
movlw D'41' ;skip next 3 bytes call skipn
movf cksum,f ;test checksum btfss status,z ;checksum must be zero retlw 1 ;here if error retlw 0 ;done with no error
EaString ;main message string ;next 69 bytes are data, but we only need to save some
movlw D'7' ;read 7 bytes movwf scount movlw month ;start of date and time RAM block movwf FSR rd1 call sbyte movwf INDF incf FSR,F decfsz scount goto rd1 movlw D'26' ;skip next 26 bytes call skipn call sbyte movwf ant call sbyte movwf vis call sbyte movwf track
movlw D'34' ;skip next 34 bytes call skipn movf cksum,f ;test checksum btfss status,z ;checksum must be zero retlw 1 ;here if error retlw 0 ;done with no error
skipn movwf scount ;last byte is ckecksum skp1 call sbyte decfsz scount goto skp1 return
; DELAY_TIME should be (ClockSpeed/4/SerialSpeed-14)/3 ; 4MHz 9600 baud would be (4000000/4/9600-14)/3 = 30 ; 4MHz 2400=134 4800=65 9600=30 19200=13 38400=4 57600=1
; 10Mhz 4800=169 DELAY_TIME equ D'30' TX_DELAY_TIME equ D'65'
TXserialDelay movlw TX_DELAY_TIME movwf serialDelayCount ; Use TX Delay goto serialDelayLoop ; use routine below
serialDelayThird movlw DELAY_TIME/3 movwf serialDelayCount ; only count 1/3 goto serialDelayLoop ; use routine below serialDelay movlw DELAY_TIME movwf serialDelayCount ; Count down from DELAY_TIME nop ; Helps with high speed serialDelayLoop decfsz serialDelayCount, F ; Countdown goto serialDelayLoop ; keep counting return ; done srt serialTransmit movwf serialData ; save the outgoing byte movlw D'10' movwf serialCount ; set the bit count clrc ; prep for start bit serialTransmitLoop bcf SERIAL_OUT ; assume send low skpc ; if sending 0 bsf SERIAL_OUT ; send high call TXserialDelay ; delay setc ; prep for stop bit rrf serialData, F ; roll serialIn bits decfsz serialCount, F ; if not complete goto serialTransmitLoop ; loop back for more return ; all done
sbyte ;read next serial byte call serialReceive iorlw 0 skpnz ;wait for start bit goto sbyte movf serialdata,w xorwf cksum,f ;add to checksum return
serialReceive btfsc SERIAL_IN ; Check for Start bit retlw 0 ; not receiving now movlw D'9' movwf serialCount ; read 9 bits call serialDelayThird ; skip third a bit serialReceiveLoop setc ; assume set carry btfss SERIAL_IN ; if receiving 0 clrc ; clear carry rrf serialData, F ; roll serialData bits call serialDelay ; delay nop ; keep timing w/ transmit decfsz serialCount, F ; if not complete goto serialReceiveLoop ; loop back for more ; Skip this as the Oncore dose not send parity ; call serialDelay ; Dump the Parity Bit... retlw 1
|