Thank you Brian!
I will try your code today.
Thanks again.
Vladimir
Thank you Brian!
I will try your code today.
Thanks again.
Vladimir
Brian Please Help!
Please post all code for “Find Field Track Routine”
I already tested your code and it successfully finding “GPRMC” string and storing data in 65 elements array (memory of PIC16F872 doesn’t allow to create bigger array).
But still cannot figure out how to find right field and extract numeric data from the string.
This is a sample of string I have:
$G,092713.867,A,4913.0722,N,12256.9039,W,1.16,73.6 5,291206,,*20
$G,092714.867,A,4913.0712,N,12256.9078,W,0.81,78.5 6,291206,,*25 and so on
Maybe I made mistake in my code?
'---------------- Definitions---------------------------------------------
define OSC 20
'------------- Define LCD registers and bits------------------------------
Define LCD_DREG PORTB 'Set LCD data port
Define LCD_DBIT 0 'Set starting data bit
Define LCD_RSREG PORTB 'Set LCD register select port
Define LCD_RSBIT 4 'Set LCD register select bit
Define LCD_EREG PORTB 'Set LCD enable port
Define LCD_EBIT 5 'Set LCD enable bit
'------------- Define DEBUG registers and bits----------------------------
define DEBUG_REG PORTC 'Set DEBUD port
DEFINE DEBUG_BIT 3 'Set DEBUG pin
DEFINE DEBUG_BAUD 4800 'Set DEBUG baud rate
DEFINE DEBUG_MODE 0 'Set DEBUG mode
'------------Allocate Variables for GPS-----------------------------------
TimeOut CON 3000 'Time out delay
baudGPS CON 16572 '16572 - 4800 baud inverted
ParseCycle var byte ' Parse counter
commacount var byte 'Commas counter
e var byte
GPSdata var byte[65] ' Data array
TEMPdata var byte ' Temp debug data
'--------------------- Pins definitions-----------------------------------
GPSin VAR PORTc.7 'pin
'-----------------------Program routine-----------------------------------
GetData:
serin2 gpsin,baudgps, timeout, nogps,[WAIT("$GPRMC")] ' find start of string
for ParseCycle = 0 to 64
serin2 gpsin, baudgps, [GPSdata[ParseCycle]]
next ParseCycle
'for parsecycle = 0 to 64 'test routine
'TEMPdata = gpsdata[parsecycle] 'test routine
'Debug TEMPdata 'test routine
FindTrackField:
commacount = 0
for ParseCycle = 0 to 64
e = GPSdata[ParseCycle]
if e = "," then commacount = commacount + 1
if commacount = 8 then gosub gettrack 'Track follows 8th comma
debug e
'debug " Gps data value ", gpsdata '10 gives MagVar - 8 gives Track
next ParseCycle
goto getdata
Nogps:
LCDOut $FE, 1 'Clear Screen
LCDOut "No GPS"
low portc.0
Pause 2300
high portc.0 'error LED flashes
pause 2300
low portc.0
goto getdata
gettrack:
lcdout $FE, $01
lcdout $fe, 1, "Time" 'not finished line
lcdout $fe, $c0, "Speed " 'not finished line
return
Brian, please push me forward one more time.
Vladimir
Last edited by vladimir059@hot; - 29th December 2006 at 16:04.
Here is a routine that will extract all fields of the RMB sentence. You can modify it for other strings.
Cheers
Brian
GetData:
' Add code here for GPRMC, etc
GetRMBData: ' capture 84 character frame in real time
serin2 rx232, 188, 2000, nogps,[WAIT("$GPRMB")] ' find header
for i = 0 to 83 'grab data stream
serin2 rx232, 188, [a[i]]
next i
' now we have an 84 character array starting with the first comma after
' $GPRMB. $GPRMB is of variable length depending on field values.
' Processing is now done while the next GPS frames pass by. Need a bigger
' RAM to handle RMB & RMC on every GPS frame.
UnpackRMB: ' unpack frame & show on SEROUT
CommaCnt = 0
for i = 0 to 83
if a[i] = "," then
CommaCnt = CommaCnt + 1 ' found a new field
serout bootout, 2, [$0D, $0A, #CommaCnt , ","]
if CommaCnt = 1 then getvalidity
if CommaCnt = 2 then getxte
if CommaCnt = 3 then getsteer
if CommaCnt = 4 then getorigin
if CommaCnt = 5 then getdestination
' if CommaCnt = 6 then getdestnlatt
' if CommaCnt = 7 then gethemisphere
' if CommaCnt = 8 then getdestlong
' if CommaCnt = 9 then geteorw
' if CommaCnt = 10 then getrangetogo
if CommaCnt = 11 then getbearing
' if CommaCnt = 12 then getclosingvelocity
if CommaCnt = 13 then getarrival
if CommaCnt = 14 then getdata 'all done so get next RMC
GetFieldData:
for j = i+1 to (i+15) 'get the next character
if a[j] = "," then
goto getnextfield
endif
serout bootout, 2, [a[j]]
next j
endif
GetNextField:
next i
goto getdata
GetValidity:
' This is needed since both Track and Bearing collapses to 0.0 when no
' GPS data is being received. This could be falsely interpreted as
' traveling due North with the destination dead ahead.
' A FailSafe check must be done here to prevent this. Currently omitted.
if a[i+1] = "V" then
serout bootout, 2, ["V = bad frame"]
goto GetNextField
endif
if a[i+1] = "A" then
serout bootout, 2, [ "A = good frame"]
goto GetNextField
endif
serout bootout, 2, [ "NO sync"]
goto GetNextField
GetXTE:
xte = 0
for j = (i+1) to (i+8) ' get (up to) the next 8 characters
if a[j]="," then xtedone ' end of field or blank field found
if a[j]<>"." then ' ignore any decimal point
e = a[j] - 48
'ASCII representation - subtract 48 to get numeric value
xte = 10* xte + e
endif
next j
XTEDone:
' at this point we have XTE * 10
serout bootout, 2, ["XTE = ", #xte/10, ".", #xte//10]
goto GetNextField
GetSteer:
if a[i+1] = "L" then
serout bootout, 2, ["Turn LEFT"]
goto GetNextField
endif
if a[i+1] = "R" then
serout bootout, 2, [ "Turn RIGHT"]
goto GetNextField
endif
serout bootout, 2, [ "NO turn info"]
goto GetNextField
GetOrigin:
'This is an alphanumeric field - needs unpacking
serout bootout, 2, ["Origin = "]
for j = (i+1) to (i+15) ' get (up to) the next 15 characters
if a[j]="," then origindone ' end of field or blank field found
serout bootout, 2, [ a[j]]
next j
OriginDone:
goto GetNextField
GetDestination:
'This is an alphanumeric field - needs unpacking
serout bootout, 2, ["Destination = "]
for j = (i+1) to (i+15) ' get (up to) the next 15 characters
if a[j]="," then destinationdone ' end of field or blank field found
serout bootout, 2, [ a[j]]
next j
DestinationDone:
goto GetNextField
GetBearing:
bearing = 0
for j = (i+1) to (i+8) ' get (up to) the next 8 characters
if a[j]="," then bearingdone ' end of field or blank field found
if a[j]<>"." then ' ignore any decimal point
e = a[j] - 48
'ASCII representation - subtract 48 to get numeric value
bearing = 10* bearing + e
endif
next j
BearingDone:
' at this point we have BEARING * 10
serout bootout, 2, ["Bearing = ", #bearing/10, ".", #bearing//10]
lcdout $FE, $01, "Track ", #track/10, ".", #track//10
lcdout $FE, $C0, "Bearing ",#bearing/10, ".", #bearing//10
goto GetNextField
GetArrival:
if a[i+1] = "A" then
serout bootout, 2, ["Arrived"]
goto GetNextField
endif
if a[i+1] = "V" then
serout bootout, 2, [ "not there yet"]
goto GetNextField
endif
serout bootout, 2, [ "NO arrival info"]
goto GetNextField
NoGPS:
lcdout $FE, $01, "No GPS data " , $FE, $C0, "Check GPS "
pause 1000
goto startup
Here is how I decode the $gprmc sentence...
Partial code below
Hope this helpsCode:GPRMC VAR BYTE[64] hh VAR BYTE 'hours mm VAR BYTE 'minutes ss VAR BYTE 'seconds sss var word 'milliseconds fix VAR WORD 'GPS fix latdeg VAR BYTE 'degrees latitude latmin VAR BYTE 'minutes latitude latminn var word 'fractional minutes latitude NS VAR BYTE 'north or south londeg VAR BYTE 'degrees longitude lonmin VAR BYTE 'minutes longitude lonminn var word 'fractional minutes longitude EW VAR BYTE 'east or west Knots VAR byte 'speed in knots (units) Knotss var byte 'speed in fractional knots course var word 'heading dy VAR BYTE 'day mt VAR BYTE 'month yr VAR BYTE 'year '============= Main Program ========================================== Main: high gpwr pause 3000 GPSin: serin2 gps,188,3000,tmout,[WAIT("$GPRMC,"),STR GPRMC\63\"$"] 'Data IN from GPS arrayread gprmc,[DEC2 hh,DEC2 mm,dec2 ss,_ wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait("."),dec4 latminn,_ wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait("."),dec4 lonminn,_ wait(","),EW,wait(","),dec knots,dec Knotss,dec course,_ wait(","),DEC2 dy,DEC2 mt,DEC2 yr] 'parse the GPS array into parts if fix = "V" then gpsin 'jump to "waiting for fix" display low gpwr high xpwr pause 1000 SEROUT2 xbtx,188,[$0D,$0A,"$GPRMC,",STR GPRMC\63] 'Data OUT to XBEE pause 500
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
Thanx so much .. I really appreciate it
Could you please provide me with GPS hardware connections with the pic ?
What are you using for the GPS? A handheld unit or a module?
Dave
Always wear safety glasses while programming.
Bookmarks