Code:
;
;
; PIC16F818
; __________
; D6-------------RAN2 |1 18| RAN1---------D5
; D7-------------RAN3 |2 17| RAN0---------D4
; LED------------RAN4 |3 16| OSC1--------XTAL
; +5V-----------!MCLR |4 15| OSC2--------XTAL
; Ground----------Vss |5 14| VDD---------+5 V
; NMEA data-------RB0 |6 13| RB7---------Not used
; Serial data out-RB1 |7 12| RB6---------Not used
; Not used--------RB2 |8 11| RB5---------LCD Enable
; Pushbutton------RB3 |9 10| RB4---------LCD Register select
; ----------
;
;====================================================================='
' Program to display returned value of a GPS on RB0
' LCD in 4-BIT mode PIC16F818 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 1500 ' Command Delay (uS)
define LCD_DATAUS 50 ' Data Delay (uS)
DEFINE OSC 4
OPTION_REG.7=0 ' Enable Pull-Up's
GPSin VAR PORTB.0
' Initialise ADC
ADCON1 = %10000100 ' Set PORTA analog and RIGHT justify result
ADCON0 = %01010001 ' Configure and turn on A/D Module channel 4 Fosc 8
PAUSE 500
'Declare variables
val VAR WORD ' final calculated adc valuesWORD' final calculated adc values
volt VAR WORD ' scaled value real part
voltd1 VAR WORD ' scaled value first decimal place
voltd2 VAR WORD ' scaled value second decimal place
i var byte ' counter
'Allocate Variables for GPS:
TimeOut CON 2000
hh VAR BYTE 'hours
mm VAR BYTE 'minutes
ss VAR BYTE 'seconds
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
EW VAR BYTE 'east or west
d VAR BYTE 'day
m VAR BYTE 'month
y VAR BYTE 'year
fix VAR WORD 'GPS fix
LCDOut $fe,$80," GPS Decoder "
LCDOut $FE,$c0, " G8VLQ Mk1 "
Pause 500
LCDOut $FE, 1 'Clear Screen
GPS: 'read GPS
SerIn2 GPSin,188,Timeout,LCD1,[wait("$GPRMC"),wait(","),DEC2 hh,DEC2 mm,DEC2 ss,wait(",")_
,fix,wait(","),DEC2 latdeg,DEC2 latmin,wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,_
wait(","),EW,wait(","),knots,wait("."),DEC2 knotsten,wait(","),DEC3 course,wait(","),DEC2 d,DEC2 m,DEC2 y]
IF fix="V" Then 'if no GPS fix
GOTO LCD1
EndIF
gosub PLL
LCD:
LCDOut $fe,$80,DEC2 d,"-",DEC2 m,"-",DEC2 y," ",#volt, ".", # voltd1,# voltd2, "Vdc" ; 80 1st line
LCDOUT $fe,$c0," ",DEC2 hh,":",DEC2 mm,":",DEC2 ss," " ; c0 2nd line
LCDOut $fe,$90," LAT: ",DEC2 latdeg,",",DEC2 latmin," ",NS ; 90 3rd line
LCDOut $fe,$d0," LON: ",DEC2 londeg,",",DEC2 lonmin," ",EW ; d0 4th line
GoTo GPS
LCD1: ; If invalid data, just shows gps string is received
LCDOut $fe,$80,#volt, ".", # voltd1,# voltd2, "Vdc" ; 80 1st line
LCDOUT $fe,$c0," No Fix " ; c0 2nd line
LCDOut $fe,$90," LAT: ",DEC2 latdeg,",",DEC2 latmin," ",NS ; 90 3rd line
LCDOut $fe,$d0," LON: ",DEC2 londeg,",",DEC2 lonmin," ",EW ; d0 4th line
goto GPS
LCD2: ; 20 character display. Put time and date on first line , removed names.
; callsign and QRA (maidenhead) on second line
LCDOut $fe,$80,DEC2 d,"-",DEC2 m,"-",DEC2 y,DEC2 hh,":",DEC2 mm ; 80 1st line
LCDOut $fe,$80," G8VLQ " ; c0 2nd line
LCDOut $fe,$90,"LAT: ",DEC2 latdeg,",",DEC2 latmin," ",NS ; 90 3rd line
LCDOut $fe,$d0,"LON: ",DEC2 londeg,",",DEC2 lonmin," ",EW ; d0 4th line
GoTo GPS
PLL:
Val = 0 ' Value returned is the average of 5 conversions
For i = 0 TO 4
ADCON0.4 = 1 ' Start conversion
NoteDone:
pause 1
IF ADCON0.4 = 1 Then NoteDone
val = val + ((ADRESH * 256)+(ADRESL))
nEXT I
VAL = VAL/5
' Calculate Volatage to 2 decimal places
volt = val * 5/1024
voltd1 = ( val * 5//1024) * 10/1024
Voltd2 = ((val *5 //1024) * 10//1024) * 10/1024
RETURN
Bookmarks