Hi,
Be careful if just counting characters. Some of the NMEA 0183 data strings have variable lengths. You need to check the specification for your device.
I'd concurr on using the hardware serial UART and a crystal.
Robert G8RPI.
Hi,
Be careful if just counting characters. Some of the NMEA 0183 data strings have variable lengths. You need to check the specification for your device.
I'd concurr on using the hardware serial UART and a crystal.
Robert G8RPI.
Thanks evrerybody, i made my prototype for GPS reading and it works perfectly i give my code as somebody can use it for similar applications
Best regards,
Leinske
' Program to display returned value of a GPS on RB1
' LCD in 4-BIT mode PIC16F628 controller 4Mhz clock Fuse PWRT BODEN
'
' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
'GPS sentence: $GPRMC,192144.62,A,5041.6058,N,00412.6124,E,0.45,3 57.74,081205,,*0B
DEFINE OSC 4
CMCON = 7
GPSin VAR PORTB.1
SW VAR PORTB.5 'optional switch for Man Over Board keeps position on EEPROM when switched on
TRISB.1=1 'define port B1 as input
TRISB.5=1 'define port B5 as input
TRISA.0=0
TRISA.1=0
TRISA.2=0
TRISA.3=0
TRISA.4=0
TRISB.3=0
PORTA=0
PORTB=0
'Allocate Variables for GPS:
TimeOut CON 3000
baudGPS CON 24764 '16572 + 8192 (bit 13)
hh VAR BYTE 'hours
mm VAR BYTE 'minutes
knots VAR WORD 'speed in knots (units)
knotsten VAR BYTE 'speed in knots (tens)
course VAR WORD 'heading
latdeg VAR BYTE 'degrees latitude
latmin VAR BYTE 'minutes latitude
NS VAR BYTE 'north or south
londeg VAR BYTE 'degrees longitude
lonmin VAR BYTE 'minutes longitude
EO VAR BYTE 'east or west
j VAR BYTE 'day
m VAR BYTE 'month
a VAR BYTE 'year
fix VAR WORD 'GPS fix
LCDOut $FE, 1 'Clear Screen
LCDOut " POP CORN"
LCDOut $fe,$c0
LCDOut " WELCOME ABOARD"
Pause 2000
LCDOut $FE, 1 'Clear Screen
LCDOut " YOUR SKIPPER"
LCDOut $fe,$c0
LCDOut " ALAIN DE VOS"
Pause 2000
LCDOut $FE, 1 'Clear Screen
GPS: 'read GPS
IF SW=1 Then 'switch for man over board
GoTo mob
EndIF
SerIn2 GPSin,baudGPS,Timeout,Nogps,[wait("$GPRMC"),wait(","),DEC2 hh,DEC2 mm,wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait(","),EO,wait(","),knots,wait("."),DEC2 knotsten,wait(","),DEC3 course,wait(","),DEC2 j,DEC2 m,DEC2 a]
IF fix="V" Then 'if no GPS fix
GoTo Nofix
EndIF
'write last valid into EEPROM
Write 0,hh
Write 1,mm
Write 2,latdeg
Write 3,latmin
Write 4,NS
Write 5,londeg
Write 6,lonmin
Write 7,EO
Write 8,j
Write 9,m
Write 10,a
GoTo LCD
LCD:
'normal display if fix ok
LCDOut $FE, 1 'Clear Screen
LCDOut "SPEED :",knots,".",DEC2 knotsten," KNT"
LCDOut $fe,$c0
LCDOut "HEADING:",DEC3 course," DEG"
Pause 3000
LCDOut $FE, 1 'Clear Screen
LCDOut "LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS
LCDOut $fe,$c0
LCDOut "LON:",DEC2 londeg,",",DEC2 lonmin," ",EO
Pause 3000
GoTo GPS
'display if no gps is present
Nogps:
Pause 1000
LCDOut $FE, 1 'Clear Screen
LCDOut " NO GPS"
Pause 1000
GoTo GPS
'display if no gps fix
Nofix:
'read last valid from EEPROM
Read 0,hh
Read 1,mm
Read 2,latdeg
Read 3,latmin
Read 4,NS
Read 5,londeg
Read 6,lonmin
Read 7,EO
Read 8,j
Read 9,m
Read 10,a
Pause 1000
LCDOut $FE, 1 'Clear Screen
LCDOut " NO GPS FIX"
LCDOut $fe,$c0
LCDOut " LAST VALID"
Pause 2000
LCDOut $FE, 1 'Clear Screen
LCDOut "DATE: ",DEC2 j,"-",DEC2 m,"-",DEC2 a
LCDOut $fe,$c0
LCDOut "TIME: ",DEC2 hh,":",DEC2 mm
Pause 2000
LCDOut $FE, 1 'Clear Screen
LCDOut "LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS
LCDOut $fe,$c0
LCDOut "LON:",DEC2 londeg,",",DEC2 lonmin," ",EO
Pause 2000
GoTo GPS
mob: 'man over board
Read 2,latdeg
Read 3,latmin
Read 4,NS
Read 5,londeg
Read 6,lonmin
Read 7,EO
Pause 1000
LCDOut $FE, 1 'Clear Screen
LCDOut " MAN OVER BOARD"
LCDOut $fe,$c0
LCDOut " POSITION"
Pause 2000
LCDOut $FE, 1 'Clear Screen
LCDOut "LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS
LCDOut $fe,$c0
LCDOut "LON:",DEC2 londeg,",",DEC2 lonmin," ",EO
Pause 2000
GoTo GPS
leinske, I notice 1 thing, I hope the MOB switch is a push button that can only be actuated 1 time or a push button switch with some kind of software flag to disable the EEPROM update after the first write as the actual MOB location will be over written. I would put some kind of flag that you must reset in a different way to maintain the MOB's actual location. Just a thought.......
Dave Purola,
N8NTA
Hi Dave,
in fact the MOB switch is a 2 positions ON/OFF toggle switch, there is also a pull down resistor on portB.5.
when MOB occures, the switch is set to ON then the program goes to the mob label, return to GPS label, test if switch is on if wel, loops to mob solong the switch is not set to off.
The writing instructions are after the switch test routine, so there are no updates of de EEPROM during the MOB action, I think it's the simplest way to do it ;o)
regards,
Leinske
Dear LEINSKE
Thanks for the source code. I just had a problem with SERIN line now its works well
Actualy I don't need to see on LCD . I catch all relevant fields of $GPRMC and I am sending by SEROUT2 command to PC by serial cable
In your code I can catch only 4 digits of the lan and lat how can I catch all lan lat as is ?
I add lanss and latss variables try to catch all strings I am loosing 0 (zero)
3202.9876 I get 32.02 and 03412.3452 I get 34.12
Thanks
Haim Rodrik
This post should be moved to the GPS thread I feel. It seems a good thread with useful code and it uses a different way of extracting the data fields than my old post in the GPS section.
Cheers
Brian
Bookmarks