CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 'SD Card pins: DO_PIN = 22 CLK_PIN = 23 DI_PIN = 24 nCS_PIN = 25 'Serial I/O pins: GPS_IN = 16 GPS_OUT = 17 PC_IN = 31 PC_OUT = 30 'Write indicator: LED_PIN = 26 'Unit ID: UNIT = "0" 'ASCII constants: CR = 13 LF = 10 OBJ sio : "FullDuplexSerial" gps : "FullDuplexSerial" sd : "fsrw" PUB start | ch, i gps.start(GPS_IN, GPS_OUT, 0, 4800) sio.start(PC_IN, PC_OUT, 0, 9600) sd.mount_explicit(DO_PIN, CLK_PIN, DI_PIN, nCS_PIN) filename[7] := UNIT dira[26]~~ waitcnt(cnt + clkfreq) gps.str(string("$PSRF100,0,4800,8,1,0*0F", CR, LF)) 'Switch to SiRF binary protocol at 4800,8,N,1 'Diable Static Navigation waitcnt(clkfreq + cnt) repeat i from 0 to 9 gps.tx(DisStatNav[i]) 'Switch back To NMEA Protocol Message ID 129, leave only GGA and RMC strings and keep speed at 4800 waitcnt(clkfreq / 2 + cnt) repeat i from 0 to 31 gps.tx(BackToNMEA[i]) repeat waitstr(string("$GPRMC,")) getstr(@time, 10) 'if (time[5] == "0" or time[5] == "5") gps.rx if (gps.rx == "A") gps.rx getstr(@lat, 9) waitstr(string("N,")) 'Change to "S" for southern hemisphere. getstr(@lon, 10) sio.str(@time) outa[26]~~ 'Turn LED on during write, so it won't be interrupted by flipping off the power. sd.popen(@filename, "a") 'Open the file to append data. sd.pwrite(@time, strsize(@time)) 'Write the time and position line to the file. sd.pclose 'Do a close to stat the file. outa[26]~ 'Turn off the LED. else sio.tx("*") PUB waitstr(strptr) | ptr, match ptr := strptr repeat while match := byte[ptr++] if (gps.rx <> match) ptr := strptr PUB getstr(strptr, len) repeat len byte[strptr++] := gps.rx DAT filename byte "gpsdata_.txt" time byte "dddddd.ddd," lat byte "ddmm.mmmm," lon byte "dddmm.mmmm",13,0 'SiRF Disable Static Navigation, Message ID 143 DisStatNav byte $A0,$A2,$00,$02,$8F,$00,$00,$8F,$B0,$B3 'Switch back To NMEA Protocol Message ID 129 at 4800 bauds, leave on GGA and RMC strings updating oce per second. BackToNMEA byte $A0,$A2,$00,$18,$81,$02,$01,$01,$00,$01 byte $00,$01,$00,$01,$01,$01,$00,$01,$00,$01 byte $00,$01,$00,$01,$00,$01,$12,$C0,$01,$61 byte $B0, $B3