'PICAXE-20X2
'NEO-6M GPS Module TX Data connected to hserin
'should work with any GPS sending NMEA messages
#picaxe 20x2
#Terminal 9600
#No_Table
#No_Data
Symbol LED = C.5
Symbol ptro = B22 'used for scratchpad pointer
Symbol ptrn = B23 'used for scratchpad pointer
Symbol ptrp = B24 'used for scratchpad pointer
Symbol spd = B25 'var for data from scratchpad
Symbol spd2 = B29 'var for data from scratchpad
Symbol hh = B26 'hour
Symbol mm = B27 'minute
Symbol ss = B28 'second
Symbol dd = B30 'day
Symbol mo = B31 'month
Symbol yy = B32 'year
Top:
hsersetup b9600_8, %00 ' set the serial to 9600 baud
Again:
ptr = 0
'wait for data $GPRMC message from gps and go to whoops if it doesn't arrive before timeout
hserin [10000,whoops],0,63,("R")
'check for "MC" (77 67) in scratchpad
get 0,spd
get 1,spd2
if spd <> 77 OR spd2 <> 67 then Again
'scan for delimiters and store positions in scratchpad starting @ 100
ptrn = 100
for ptr = 0 to 62
if @ptr = "," and ptrn < 127 then
put ptrn,ptr
ptrn = ptrn + 1
endif
next
'get the time/date from scratchpad
get 100,ptrp
gosub getdata
hh = spd
gosub getdata
mm = spd
gosub getdata
ss = spd
get 108,ptrp
gosub getdata
dd = spd
gosub getdata
mo = spd
gosub getdata
yy = spd
sertxd (#hh,":",#mm,":",#ss," ",#mo,"-",#dd,"-",#yy,CR,LF)
goto Again
getdata:
'gets time/date data and converts ASCII to numeric
ptrp = ptrp + 1
ptrn = ptrp + 1
get ptrp, spd
get ptrn, spd2
spd = spd - 48
spd2 = spd2 - 48
spd = spd * 10 + spd2
ptrp = ptrp+1
return
whoops:
SerTxd ("GPS Data Fail")
SerTxD (CR, LF)
Pause 100
GoTo Again
ledflash:
High LED
Pause 200
Low LED
Pause 200
Return