Code:
'****************************************************************
'* Name : Fly-GPS_V1-0-3-0_16F690 *
'* Author : FLOTUL *
'* Notice : Copyright (c) 2006 Flotulopex & Co. *
'* : All Rights Reserved *
'* Date : 22.04.2010 *
'* Version : 1.0 *
'* Notes : FOR USE WITH MPX4115A pressure sensor *
'* : *
'****************************************************************
data 1,0,3,0 'major/minor HW-SF
'Version history
'1-0-3-0:
' Changed DOGM display settings to work under 3,3V instead of 5V
' Added switch to scroll through different displays
'
'1-0-2-5:
' Display distance instead of course
'
'1-0-2-4:
' Working version
'-------------------------------------------------------------------------------
' PIC 16F690 Fuses
@ DEVICE FCMEN_OFF
@ DEVICE IESO_OFF
@ DEVICE BOD_OFF
@ DEVICE CPD_OFF
@ DEVICE PROTECT_OFF
@ DEVICE MCLR_OFF
@ DEVICE PWRT_OFF
@ DEVICE WDT_OFF
@ DEVICE XT_OSC
'@ DEVICE INTRC_OSC_NOCLKOUT
' Registers 76543210
OPTION_REG = %10000000 'PORT A&B Pull-Ups disabled (look WPUA & WPUB)
'OSCCON = %01100000 'Internal RC set to 4Mhz - not to be used with XTal
ANSEL = %00000000 'Disable analog inputs Channels 0 to 7
ANSELH = %00000000 'Disable analog inputs Channels 8 to 11
WPUB = %00000000 'Disable weak pull-ups
ADCON0 = %00000000 'A/D Module is OFF
CM1CON0 = %00000000 'Comparator1 Module is OFF
CM2CON0 = %00000000 'Comparator2 Module is OFF
INTCON = %00000000 'INTerrupts CONtrol
TRISA = %00000000 'Set Input/Output (0 to 5)
PORTA = %00000000 'Ports High/Low (0 to 5)
TRISB = %00010000 'Set Input/Output (4 to 7)
PORTB = %00000000 'Ports High/Low (4 to 7)
TRISC = %00000000 'Set Input/Output (0 to 7)
PORTC = %00000000 'Ports High/Low (0 to 7)
'-------------------------------------------------------------------------------
' LCD circuitry
'- ( 1) Vss - GND
'- ( 2) Vdd / Vcc +5V
'- ( 3) Vee / Vo / Contrast adjust / Pot 4k7(1-2-W3) or R2k2(GND-3)
'PORTC.2 ( 4) RS
'- ( 5) R/W -> to Vss
'PORTC.3 ( 6) E
'PORTC.4 (11) D4
'PORTC.5 (12) D5
'PORTC.6 (13) D6
'PORTC.7 (14) D7
DEFINE LCD_DREG PORTC 'LCD data port
DEFINE LCD_DBIT 4 'LCD data starting PORT.bit (0 or 4)
DEFINE LCD_RSREG PORTC 'LCD register select port
DEFINE LCD_RSBIT 2 'LCD register select bit
DEFINE LCD_EREG PORTC 'LCD enable port
DEFINE LCD_EBIT 3 'LCD enable bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
' SERIAL communication connections (may need level-shifter such as MAX232 chip)
'PC's TX pin on DB9=3 or DB25=2
'PC's RX pin on DB9=2 or DB25=3
'GND: DB9=5 or DB25=7
' 13 is carriage return and 10 is line feed
'-------------------------------------------------------------------------------
INIT:
clear
Ctr_A var byte 'Counter
Ctr_B var byte 'Counter
Cnt_E var byte 'Counter end value
GPS_D var byte(80)'Incomming data bit array
Spd_U var word 'Speed Units
Cou_U var word 'Course Units
AltMSL var word 'Altitude above Mean Sea Level
Cdls var byte(4) 'Cardinals holding variables
Tenths var byte 'Holds tenths
CommaCnt var byte 'comma count
Temp var byte
PosFix var byte 'GPS Position Fix Indicator
Sats var byte 'Number of used Satellites
GPSfrom var PORTB.4 'use a TTL I/O port on PIC!
GPSto var PORTB.5 'use a TTL I/O port on PIC!
GPSbps var word
GPSbps = 32852 'Open,True,N,9600bps (TTL level)
'32956 'Open,True,N,4800bps (TTL level)
Timeout con 255 'seems to be a problem in SERIN2 if > 255
' Custom character definition
LCDOUT $FE,$40,$0C,$12,$12,$0C,$00,$00,$00,$00 'character 0 = "°"
lcDOUT $FE,$48,$14,$18,$14,$00,$1E,$15,$15,$00 'character 1 = "km"
LCDOUT $FE,$50,$1E,$15,$15,$00,$1E,$15,$15,$00 'character 2 = "m/m"
'-------------------------------------------------------------------------------
MAIN:
' DOGM LCD display Mandatory settings
pause 1000 'Time to settle Vdd (THIS IS VERY IMPORTANT!!!)
lcdout $FE, $29 'Function Set: 4 bits bus mode
lcdout $FE, $1C 'Bias set
lcdout $FE, $55 'Power control + Contrast (HiByte)(for 5V=$52/3,3V=55)
lcdout $FE, $6D 'Follower control (5V=$69/3,3V=6D)
Lcdout $FE, $75 'Contrast (LowByte)
lcdout $FE,2,"Fly GPS "
pause 3000
lcdout $FE,2,"RL v2.4 "
pause 2000
'-------------------------------------------------------------------------------
' SEROUT initialisation
serout2 GPSto,Gpsbps,[,13,10] 'don't know why, but must be!!!
' Set GPS BaudRate to 4800 (
'serout2 GPSto,Gpsbps,["$PMTK251,4800,*14",13,10] 'set Baudrate to 4800bps
'-------------------------------------------------------------------------------
GPGGA:
' Get GPS GGA sentence and store it into GPS_D var (max 80 caracters)
ctr_a = 0
commacnt = 0
SERIN2 GPSfrom,Gpsbps,[WAIT("$GPGGA,"),str GPS_D\80\"*"]
' Get UTC time
lcdout $FE,2,Gps_d(0),Gps_d(1),":",Gps_d(2),Gps_d(3),":",Gps_d(4),Gps_d(5)
pause 1000
' extract POSITION FIX data after 5th comma
ctr_a = 0
posfix = 0
while commacnt < 5
if gps_d(ctr_a) = "," then commacnt = commacnt + 1
ctr_a = ctr_a + 1
wend
posfix = gps_d(ctr_a)-48
if posfix <1 then
ctr_b = 0
lcdout $FE,2,"No Fix! "
goto gpgga:
else
ctr_b = ctr_B + 1
if ctr_b = 10 then
serout2 GPSto,Gpsbps,["$PSRF103,04,00,00,01*20",13,10] 'set OFF RMC
CHECK_VTG:
SERIN2 GPSfrom,Gpsbps,Timeout,NoVTG,[WAIT("$GPVTG")]
goto GPVTG:
NoVTG:
serout2 GPSto,Gpsbps,["$PSRF103,05,00,01,01*20",13,10] 'set ON VTG
goto CHECK_VTG:
endif
endif
if posfix = 1 then lcdout $FE,2,"Fix: SPS"
if posfix = 2 then lcdout $FE,2,"Fix:Diff"
if posfix = 3 then lcdout $FE,2,"Fix: PPS"
'lcdout $FE,2,"Fix: ", dec posfix, " "
pause 1000
' go to next data field (SATELLITES USED)
ctr_a = ctr_a + 2
' extract SATELLITES USED data
sats = 0
while gps_d(ctr_a) != ","
sats = 10 * sats + (gps_d(ctr_a)-48)
ctr_a = ctr_a + 1
WEND
lcdout $FE,2,"Sats: ", dec2 sats
pause 1000
' go to next data field (ALTITUDE)
ctr_a = 0
commacnt = 0
while commacnt < 8
if gps_d(ctr_a) = "," then commacnt = commacnt + 1
ctr_a = ctr_a + 1
wend
' extract ALTITUDE data
altmsl = 0
while gps_d(ctr_a) != "."
altmsl = 10 * altmsl + (gps_d(ctr_a)-48)
ctr_a = ctr_a + 1
WEND
' data "right" align data
lcdout $FE,1,"Alt"
if altmsl > 999 then lcdout $FE,$83,dec4 altmsl,2
if altmsl > 99 then lcdout $FE,$84,dec3 altmsl,2
if altmsl > 9 then lcdout $FE,$85,dec2 altmsl,2
if altmsl <= 9 then lcdout $FE,$86,dec1 altmsl,2
pause 800
goto GPGGA:
'-------------------------------------------------------------------------------
GPVTG:
' Get VTG sentence and store it into GPS_D var until "*" is found
SERIN2 GPSfrom,Gpsbps,[WAIT("$GPVTG,"),str GPS_D\80\"*"]
'No data: $GPVTG,,T,,M,,N,,K*4E
'Data : $GPVTG,206.86,T,,M,0.47,N,0.9,K*60
'no data yet (not moving yet)
if gps_d(0) = "," then
lcdout $FE,2,"No Data!"
goto GPVTG:
endif
' extract COURSE data
ctr_a = 0
cou_u = 0
while gps_d(ctr_a) != "."
Cou_u = 10 * cou_u + (gps_d(ctr_a)-48)
ctr_a = ctr_a + 1
WEND
' locate SPEED data after 6th comma
ctr_a = 0
commacnt = 0
while commacnt < 6
if gps_d(ctr_a) = "," then commacnt = commacnt + 1
ctr_a = ctr_a + 1
wend
' extract SPEED data
spd_u = 0
while gps_d(ctr_a) != "."
spd_u = 10 * spd_u + (gps_d(ctr_a)-48)
ctr_a = ctr_a + 1
WEND
' go to next character after the dot
ctr_a = ctr_a + 1
' if speed tenths >= 5, round up speed to +1
Tenths = gps_d(ctr_a)-48
if tenths >= 5 then spd_u = spd_u + 1
lcdout $FE,1
' convert course in cardinals
if spd_u = 0 then ' If the speed is zero, don't display any course
lcdout $FE,2,"----"
else
' ' eight cardinals displayed
' if cou_u >= 0 then ctr_a = 0
' if cou_u >= 34 then ctr_a = 8
' if cou_u >= 80 then ctr_a = 16
' if cou_u >= 124 then ctr_a = 24
' if cou_u >= 170 then ctr_a = 32
' if cou_u >= 214 then ctr_a = 40
' if cou_u >= 260 then ctr_a = 48
' if cou_u >= 304 then ctr_a = 56
' if cou_u >= 350 then ctr_a = 0
' sixteen cardinals displayed
if cou_u >= 0 then ctr_a = 0
if cou_u >= 11 then ctr_a = 4
if cou_u >= 34 then ctr_a = 8
if cou_u >= 57 then ctr_a = 12
if cou_u >= 80 then ctr_a = 16
if cou_u >= 101 then ctr_a = 20
if cou_u >= 124 then ctr_a = 24
if cou_u >= 147 then ctr_a = 28
if cou_u >= 170 then ctr_a = 32
if cou_u >= 191 then ctr_a = 36
if cou_u >= 214 then ctr_a = 40
if cou_u >= 237 then ctr_a = 44
if cou_u >= 260 then ctr_a = 48
if cou_u >= 281 then ctr_a = 52
if cou_u >= 304 then ctr_a = 56
if cou_u >= 327 then ctr_a = 60
if cou_u >= 350 then ctr_a = 0
cnt_e = CTR_A + 3
ctr_b = 0
FOR ctr_A = ctr_A TO cnt_e
lookup ctr_a,_
["-N- N-NEN-E E-NE-E- E-SES-E S-SE-S- S-SOS-O O-SO-O- O-NON-O N-NO"],Temp
Cdls(ctr_b) = temp
ctr_b = ctr_b + 1
NEXT ctr_a
lcdout $FE,2,Cdls(0),Cdls(1),Cdls(2),Cdls(3)
endif
if spd_u > 99 then lcdout $FE,$84,dec3 spd_u,1
if spd_u > 9 then lcdout $FE,$85,dec2 spd_u,1
if spd_u <= 9 then lcdout $FE,$86,dec1 spd_u,1
goto GPVTG:
and there is it's corresponding error list from MCS:
Bookmarks