Parsing GPS NMEA $GPGGA $GPRMC with a 28X1 to display TIME
For those wanting a start on how to read NMEA strings from a GPS, I found this works well enough. It does not get every string, but it will get every second or third string.
If you remove the comments the sertxd's you can see which NMEA string was parsed.
For those wanting a start on how to read NMEA strings from a GPS, I found this works well enough. It does not get every string, but it will get every second or third string.
If you remove the comments the sertxd's you can see which NMEA string was parsed.
Code:
'Written on 21-Feb-2009
'For PicAxe28X1 and Serial GMouse GPS
'GPS Serial input on pin 18 ser RX
'LED on pin 28
SYMBOL Hours = B1
SYMBOL Minutes = B3
SYMBOL Seconds = B5
SYMBOL MilliSeconds = W6
'Blink LED
loop1:high 7:pause 10 :low 7:pause 1000
main:
hsersetup B4800_4, %00 ‘baud 4800 at 4MHz
hserin [2000,nodata],0,80,("$") ‘wait for $ then receive 80 bytes into sp
ptr = 0 ‘reset scratchpad pointer
gettime: 'GPGGA GPRMC sentences have the time HHMMSS.sss
B0=@ptrinc : if B0<>"G" then mainx
B0=@ptrinc : if B0<>"P" then mainx
B0=@ptrinc : if B0<>"G" then lookforR
B0=@ptrinc : if B0<>"G" then mainx
B0=@ptrinc : if B0<>"A" then mainx
'sertxd ("$GPGGA",cr,lf)
goto TXControllerInfo
lookforR:
if B0<>"R" then mainx
B0=@ptrinc : if B0<>"M" then mainx
B0=@ptrinc : if B0<>"C" then mainx
'sertxd ("$GPRMC",cr,lf)
'============================================================
TXControllerInfo:
B0 = @ptrinc 'skip comma after NMEA Sentence ID
B0 = @ptrinc - 48 'get tens of hour value
Hours = B0 * 10 + @ptrinc - 48 'add units of the hour value
B2 = @ptrinc - 48 'get tens of minutes value
Minutes = B2 * 10 + @ptrinc - 48 'add units of the minutes value
B4 = @ptrinc - 48 'get tens of the seconds value
Seconds = B4 * 10 + @ptrinc - 48 'get units of the seconds value
B0 = @ptrinc 'skip decimal
B6 = @ptrinc - 48 'get 1st digit of milliseconds
B7 = @ptrinc - 48 'get 2nd digit of milliseconds
B8 = @ptrinc - 48 'get 3rd digit of milliseconds
MilliSeconds = B6*10 + B7*10 + B8 'calc milliseconds , NOTE the tricky math here with B6*10 not *100 as you would think
sertxd (#Hours,":",#Minutes,":",#Seconds,".",#MilliSeconds," UTC",cr,lf)
goto loop1
nodata:
sertxd ("no data",cr,lf)
goto loop1
mainx:
;sertxd ("x")
goto loop1
Last edited: