Code:
'* Author : LEONARDO BILALIS *
'* Notice : Copyright (c) 2018 [LEONARDOS BILALIS] *
'* : All Rights Reserved *
'* Date : 12/5/2018 *
'* Version : 1.0 *
'* Notes : This is an G.TOP015 G9 MT3333 gps module *
'* : *
'****************************************************************
@ ERRORLEVEL -306 ; this command prevents the compiler to give you a notice of
; crossing page boundary - make sure bits are set
@ __config _CONFIG1, _HS_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF
Include "MODEDEFS.BAS"
DEFINE OSC 8
OSCCON=%01111000 '8 Mhz
CMCON = 7 'turn comparators off
ANSEL = 0 'All digital
PORTB = 0 'make low all ports at B range
input portb.0 'make input portb.0
'-----------------------------------------------------------------------------/
' [ ULCD 1'44 4D System ] /
'---------------------------------------------------------------------------/
' "o" degree character is manual created for degree value
'----------------------------------------------------------------------------/
' [ PIC Variables ] /
'--------------------------------------------------------------------------/
PWRLED var PORTb.1 ; this shows that the initialization is finished
LCD var PORTb.2 ; to LCD operation
GPS_TX var PORTb.0 ; info from GPS
GPS_RX var PORTb.4 ; COMMANDS TO GPS
Testled var PORTb.5
dots var byte
dots = 21
countremain var byte ; we use a countremain to check the incoming from portb.0
pause 1000
;serout2 gps_rx,84, ["$PMTK330,62*1A",13,10] ' check MTK manual configuration
' --------------------[ GPS Variables for NMEA sentenses ]---------------------/
' /
' $GPRMC,090045.000,A,3823.6645,N,02353.3600,E,0.02,195.80,170518,,,A*62 /
' $GNGGA,140405.000,3823.6010,N,02353.3054,E,1,9,0.88,0.8,M,35.9,M,,*40 /
' /
'-------------------------------------------------------------------------/
Timeout con 2000
hh var byte 'hours
mm var byte 'minutes
ss var byte 'seconds
sss var word 'milisecs
degrees VAR BYTE 'latitude/longitude degrees
minutes VAR BYTE 'latitude/Longitude minutes
minutesD VAR word 'latitude/LONGITUDE DECIMAL MINUTES
dir VAR BYTE ' direction (latitude: 0 = N, 1 = S / longitude: 0 = E, 1 = W)
degrees2 VAR BYTE 'latitude/longitude degrees
minutes2 VAR BYTE 'latitude/Longitude minutes
minutesD2 VAR word 'latitude/LONGITUDE DECIMAL MINUTES
dir2 var byte ;direction (latitude: 0 = N, 1 = S / longitude: 0 = E, 1 = W)
SatNo VAR BYTE 'number of satellites connected
knots var word 'speed over ground
knots2 var byte 'speed over ground
course var word 'course
course2 var byte 'course
day var byte 'day
month var byte 'month
year var byte 'year
i var word
GNRMC var word 'protocol
GNGGA var WORD 'protocol
FIX var word 'fix sat V/A
Modefix var byte 'mode fix 1 or 2 or 3 depens
horizon var byte
precision var byte
meter var byte
METERS var byte
Meters2 var byte
Day_added var byte
Numofdays var byte 'these are the days of each months
ndays var byte [13] 'create an array with 13 byte location for Months values
' -------------------------------------------------------------------------/
' [ LCD Initialization ] /
'------------------------------------------------------------------------/
high testled
serout2 LCD,32,[$55] ' uOLED Initialize
pause 2000
serout2 lcd,32,[$56,$01]
pause 1000
serout2 lcd,32,[$45] ' clear the lcd
pause 500
serout2 lcd,32,[$55]
pause 500
serout2 lcd,32,[$45] ' clesr the lcd
pause 500
serout2 lcd,32,[$73,$00,$03,$11,$ff,$ff," Leonardo Bilalis",$00]
pause 200
serout2 lcd,32,[$73,$02,$06,$10,$ff," Copyright 2018",$00]
pause 3000
serout2 lcd,32,[$45]
pause 1000
serout2 lcd,32,[$73,$02,$06,$10,$ff,$ff," GPS.........",$00]
pause 500
serout2 lcd,32,[$45]
pause 200
'----------------------------------------------------------------------/
' [ After the lcd initialization we power the Led at PIC ] /
'--------------------------------------------------------------------/
HIGH pwrled
'----------------------sent a centence to gps------------------------
'Here i was planning to send a code to the GPS, i will find out the way later once i fix the Calendar part
;serout gps_rx,84,[$PMTK_103*30,,,]
;pause 100
'-------------------------------------------------------------------/
' [MAIN Program] /
'-----------------------------------------------------------------/
Main:
'-------------------------------------------------------------------------------/
' /
' [ Example NMEA Sentense of GNRMC ] /
' [$GNRMC,090045.000,A,3823.6645,N,02353.3600,E,0.02,195.80,170518,,,A*62] /
' /
'--------------------------------------------------------------------------/
serin2 gps_tx,84,timeout,lostcable,[wait("$GNRMC"),_ ;we wait for $GNRMC
wait(","),dec2 hh,dec2 mm,dec2 ss,wait("."),dec3 sss,_ ;we wait for 090045.000 which is the time when we got the info
wait(","),fix,_ ;we wait for A
wait(","),dec2 degrees,dec2 minutes,wait("."),dec4 minutesd,_ ;we wait for 3823.6645
wait(","),dir,_ ;we wait for N/S
wait(","),dec3 degrees2,dec2 minutes2,wait("."),dec4 minutesd2,_;we wait for 02353.3600
wait(","),dir2,_ ;we wait for E/W
wait(","),SKIP 4,_ ; i also used SKIP command but doesnt look like the compiler identified it as long as is not in Capital / Bold. But seems to be working and compiling the code.
wait(","),SKIP 6,_
wait(","),dec2 day,dec2 month,dec2 year] ;we wait for 170518
pause 100
'wait(","),dec1 knots,wait("."),dec2 knots2,_ ;we wait for 0.02
'wait(","),dec3 course,wait("."),dec2 course2,_ ;we wait for 195.80
'------------------------------------------------------------------------------/
' /
' [ Example NMEA Sentense of GNGGA ] /
' [$GNGGA,140405.000,3823.6010,N,02353.3054,E,1,9,0.88,0.8,M,35.9,M,,*40 /
' /
'-------------------------------------------------------------------------/
serin2 gps_tx,84,timeout,lostcable,[wait("$GNGGA"),_ ;we wait for GNGGA
wait(","),SKIP 37,_
wait(","),dec2 satno,_
wait(","),SKIP 19]
pause 100
;wait(","),dec2 hh,dec2 mm,dec2 ss,wait("."),dec3 sss,_ ;we wait for 140405.000 which is the time when we got info
;wait(","),dec2 degrees,dec2 minutes,wait("."),dec4 minutesd,_ ;we wait for 3823.6010 longitude
;wait(","),dir,_ ;we wait for the N/S
;wait(","),dec3 degrees2,dec2 minutes2,wait("."),dec4 minutesd2,_;we wait for 02353.3054 latitude
;wait(","),dir2,_ ;we wait for E/W
;wait(","),modefix,_ ;we wait for modefix 1,2 or 3 check gps manual for NMEA
;wait(","),dec2 satno,_ ;we wait for the number of fixed satellites, this is impoetant info
;wait(","),dec3 horizon,dec precision,_ ;we wait for horizon
;wait(","),meter,dec2 METERS,dec Meters2] ;we wait for the meters
'---------------------------------------------------------------------------------/
' Here if the GPS module havent been fixed to any satellite will jump to notfix /
'-------------------------------------------------------------------------------/
if fix = "V" then notfix
pause 100
'-----------------------------------------------------------------------------/
' [ Return from notfix ] /
' [ We clear any character on the display ] /
'--------------------------------------------------------------------------/
serout2 lcd,32,[$45] 'Clear the ulcd 1'44
pause 500
'-----------------------------------------------------------------------------/
' Here we start the calendar conversion /
'---------------------------------------------------------------------------/
; arraywrite ndays,13,NDAY,[0,31,28,31,30,31,30,31,31,30,31,30,31] ; This Code doesnt compile as there is a syntax error.
; numofdays=ndays[month]
day_added = 0
hh = hh + 3 'the Hour from GPS is UTC so for our country in Greece we add +3
if hh > 23 then 'if the hh+3 hour is greater than 23 (23:00) then
day_added = 1 'we check the day added is true
endif
hh = hh//24 'but the hour not exceed the 24 so go to 00:00
if day_added = 1 then 'now if day added is true
day = day + 1 'then ADD 1 day
if day > Numofdays then 'if day is greater than the numbers of the days in this month
lookup month,[0,31,28,31,30,31,30,31,31,30,31,30,31],numofdays
day = 1 'then day goes to number 1
if month > 12 then '
month = 1 'then day goes to number 1
year = year +1 'and the year will increase by 1
if ((year//4 = 0) and (year//400 != 0)) then
year = 1
if month = 2 then
numofdays = numofdays + 1
endif
endif
endif
endif
endif
'--------------------------------------------------------------------------/
' here is where the code dispays the stored info from the NMEA sentenses /
'------------------------------------------------------------------------/
serout2 lcd,32,[$73,$03,$00,$00,$FF,$FF," Protocol:","NMEA",$00]
pause 100
serout2 lcd,32,[$73,$01,$02,$01,$07,$E0," Date:",dec2 day,"/",dec2 month,"/",dec2 year,$00]
pause 100
serout2 lcd,32,[$73,$00,$04,$00,$FF,$E0," TIME: ",dec2 hh," :",dec2 mm," :",dec2 ss,$00]
pause 100
serout2 lcd,32,[$73,$00,$07,$00,$FF,$FF," Satellites",$00]
pause 100
serout2 lcd,32,[$73,$03,$09,$11,$07,$FF,dec2 satno,$00]
pause 100
serout2 lcd,32,[$73,$00,$07,$00,$FF,$FF," Fixed",$00]
pause 100
serout2 lcd,32,[$73,$0B,$09,$11,$07,$FF,fix," 3D",$00]
pause 100
serout2 lcd,32,[$73,$00,$0B,$00,$ff,$ff," Lat : ",dec2 degrees,"*",dec2 minutes,"'",dec4 minutesd,"@"," ",$00]
pause 100
serout2 lcd,32,[$73,$BE,$0B,$10,$f8,$00,dir,$00]
pause 100
serout2 lcd,32,[$73,$00,$0D,$00,$ff,$ff," Lon :",dec3 degrees2,"*",dec2 minutes2,"'",dec4 minutesd2,"@"," ",$00]
pause 100
serout2 lcd,32,[$73,$BE,$0D,$10,$f8,$00,dir2,$00]
;serout2 lcd,32,[$73,$00,$0C,$00,$ff,$ff,"GND SPEED : ",(dec knots,".",dec2 knots2)*/1.852,$00]
;pause 200
;serout2 lcd,32,[$73,$00,$0E,$00,$ff,$ff,"Meters : ",dec2 METERS,dec Meters2,$00]
pause 5000
serout2 lcd,32,[$45] ' clears the LCD
pause 100
goto main
'-----------------------------------------------------------------------------/
' [ SUB ROUTINES ] /
'---------------------------------------------------------------------------/
'-----------------------------------------------------------------------------/
' [ Calendar days in Months ] /
'---------------------------------------------------------------------------/
'The following i was planning to use it with ARRAYWRITE but cant seem i can get it working.
NDAY:
ndays[0] = 0
ndays[1] = 31 'January
ndays[2] = 28 'February
ndays[3] = 31 'March
ndays[4] = 30 'April
ndays[5] = 31 'May
ndays[6] = 30 'June
ndays[7] = 31 'July
ndays[8] = 31 'August
ndays[9] = 30 'September
ndays[10] = 31 'October
ndays[11] = 30 'November
ndays[12] = 31 'December
'-----------------------------------------------------------------------------/
' [ Waiting for GPS signal ] /
'---------------------------------------------------------------------------/
notfix: ' Still looking for fixed signal
serout2 lcd,32,[$73,$00,$03,$11,$07,$ff," Waiting for GPS",$00]
pause 100
hh = hh + 3
hh = hh//24
serout2 lcd,32,[$73,$03,$06,$10,$ff,$E0," Time:",dec2 hh," :",dec2 mm," :",dec2 ss,$00]
pause 1000
serout2 lcd,32,[$73,$00,$08,$10,$07,$ff,rep "." \dots,$00]
pause 200
serout2 lcd,32,[$45] ' clears the LCD
pause 100
goto main 'returns to main
'-----------------------------------------------------------------------------/
' [ Connection lost Please check the GPS ] /
'---------------------------------------------------------------------------/
lostcable:
serout2 lcd,32,[$73,$00,$03,$11,$f8,$00," Connection lost",$00]
pause 200
serout2 lcd,32,[$73,$01,$06,$10,$07,$FF," Please check cable",$00]
pause 2000
serout2 lcd,32,[$45] ' clears the LCD
pause 100
goto main
'-------------------------------------------------------------------------/
' GREEK TIME and Correcrion /
'-----------------------------------------------------------------------/
' at the moment this is not connected to any part of the code
;Plusthree:
; hh = hh + 3
; IF hh = 25 THEN hh = 0
;RETURN
'---------------------------------------------------------------------------/
' [ CLEAR LCD ] /
'-------------------------------------------------------------------------/
Clearlcd:
serout2 lcd,32,[$45]
pause 500
RETURN
Regarding the following part of the code, MARKED items with RED by Richard i will fix it on my next message. I think it is clear what needs to be done. Thanks once again.
Bookmarks