Code:
'
' Program to display returned value of a GPS on RB0
' LCD in 4-BIT mode PIC16F628 controller 4Mhz clock Fuse PWRT BODEN
'
'GPS sentence: $GPRMC,192144.62,A,5041.6058,N,00412.6124,E,0.45,3 57.74,081205,,*0B
Define LCD_DREG PORTA ' Port for LCD Data
Define LCD_DBIT 0 ' Use upper 4 bits of Port
Define LCD_RSREG PORTB ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 4 ' Port Pin for RS bit (pin9)
Define LCD_EREG PORTB ' Port for Enable (E) bit
Define LCD_EBIT 5 ' Port Pin for E bit (pin7)
Define LCB_BITS 4 ' Using 4-bit bus
Define LCD_LINES 4 ' Using 2 line Display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
define LCD_DATAUS 50 ' Data Delay (uS)
DEFINE OSC 4
CMCON = 7
OPTION_REG.7=0 ' Enable Pull-Up's
GPSin VAR PORTB.0
LED VAR PortA.4 ' flash per second
TRISA.0=0
TRISA.1=0
TRISA.2=0
TRISA.3=0
TRISA.4=0 ; LED
PAUSE 500
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 $fe,$80," GPS Decoder "
LCDOut $FE,$c0, " G8VLQ "
Pause 2000
LCDOut $FE, 1
GPS: 'read GPS
SerIn2 GPSin,baudGPS,Timeout,[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]
flash: ;not accurate pps
led high
led low
IF fix="V" Then 'if no GPS fix
GOTO LCD1
EndIF
LCD: ; LATER put time and date on first line , remove names
; callsign and QRA (maidenhead) on second line
LCDOut $fe,$80,"DATE: ",DEC2 j,"-",DEC2 m,"-",DEC2 a ; 80 1st line
LCDOUT $fe,$c0,"TIME: ",DEC2 hh,":",DEC2 mm ; c0 2nd line
LCDOut $fe,$94,"LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS ; 94 3rd line
LCDOut $fe,$d4,"LON:",DEC2 londeg,",",DEC2 lonmin," ",EO ; d4 4th line
GoTo GPS
LCD1: ; If invalid data, just shows gps string is received
LCDOut $fe,$80," Invalid data " ; 80 1st line
LCDOUT $fe,$c0," No Fix " ; c0 2nd line
LCDOut $fe,$94,"LAT:",DEC2 latdeg,",",DEC2 latmin," ",NS ; 94 3rd line
LCDOut $fe,$d4,"LON:",DEC2 londeg,",",DEC2 lonmin," ",EO ; d4 4th line
GoTo GPS
locator:
lonloc1=londeg + lonmin + 180
lonloc2=lonloc1/20
lonloc3=lonloc1//20
maid1=lonloc2+1
lookup maid1 ; first main letter
lonloc4=lonloc3//2
maid3=lonloc3/2 ;first number
maid5=lonloc4*12+1
lookup maid5 ; 1st 2nd letter
latloc1=latdeg + latmin + 90
latloc2=latloc1/10+1
latloc3=latloc1//10
maid1=latloc2+1
lookup maid2 ; second main letter
maid4=latloc3 ; second number
maid6=latloc3*24+1
lookup maid6 ; 2nd 2nd letter
maidenhead=maid1, maid2, maid3, maid4, maid5, maid6
speed:
LCDOUT $fe,1
LCDOut $fe,$80,"SPEED :",knots,".",DEC2 knotsten," KNT"
LCDOut $fe,$c0,"HEADING:",DEC3 course," DEG"
END
Bookmarks