Code:
'**********************************************************************
'* Name : 18F26K22.BAS *
'* Author : [Leonardo Bilalis] *
'* Notice : Copyright (c) 2018 [Leonardo Bilalis] *
'* : All Rights Reserved *
'* Date : 18/Jul/2018 *
'* Version : 1.0 *
'* Notes : This is a GPS Tracker based on the following components *
'* : PIC18F26K22 or PIC18F46K22 @ 64Mhz *
'* : MKT 3333 or 3339 GPS MODULE *
'* : 4D Systems ULCD Goldelox or Picasso Graphic Processor *
'**********************************************************************
'**********************************************************************
'* AXN5.1.1_8524_3333_1152.1151100.1 *
'**********************************************************************
' --------------------[ 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 /
' $GPGSA,A,3,18,08,10,11,14,27,22,32,01,,,,2.62,1.11,2.37*03 /
' $GPVTG,215.60,T,,M,0.44,N,0.82,K,A*37 /
' /
'-----------------------------------------------------------------------/
' When the GPS Module is POWERED ON, then the following sentenses are received.
' $PMTK011,MTKGPS*08
' $PMTK010,001*2E
' $PMTK010,002*2D
'*********************************************************************************
@ ERRORLEVEL -306 ; this command prevents the compiler to give you a notice of *
; crossing page boundary - make sure bits are set *
'*********************************************************************************
#CONFIG ; The PBP configuration for the PIC18F26K22 is:
; CONFIG FOSC = RCIO6 ; External RC oscillator
CONFIG FOSC = HSHP ; HS oscillator (high power > 16 MHz)
;*---------------------------------4x PLL ENABLE--------------------------------------*|
;* 4X PLL Enable *|
;* CONFIG PLLCFG = OFF ;Oscillator used directly *|
CONFIG PLLCFG = ON ;Oscillator multiplied by 4 *|
;*------------------------------------------------------------------------------------*|
;
; Primary clock enable bit
; CONFIG PRICLKEN = OFF ;Primary clock can be disabled by software
CONFIG PRICLKEN = ON ;Primary clock enabled
;
; Fail-Safe Clock Monitor Enable bit
CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor disabled
; CONFIG FCMEN = ON ;Fail-Safe Clock Monitor enabled
;
; Internal/External Oscillator Switchover bit
CONFIG IESO = OFF ;Oscillator Switchover mode disabled
; CONFIG IESO = ON ;Oscillator Switchover mode enabled
CONFIG BOREN = SBORDIS ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
;*--------------------------------------------------------------------------------------------------------;|
CONFIG WDTEN = ON ; WDT is always enabled. SWDTEN bit has no effect ;|
CONFIG WDTPS = 32768 ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale;|
;*--------------------------------------------------------------------------------------------------------;|
CONFIG PWRTEN = ON
CONFIG HFOFST = ON ; HFINTOSC output and ready status are not delayed by the oscillator stable status
CONFIG MCLRE = EXTMCLR ; MCLR pin enabled, RE3 input pin disabled
CONFIG LVP = OFF ; Single-Supply ICSP disabled
CONFIG XINST = OFF ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
CONFIG DEBUG = OFF ; Disabled
;*----------------------------------------------------------------------------------|
;*---------------Available configuration settings for PIC18F26K22-------------------|
;*----------------------------------------------------------------------------------|
;
; Oscillator Selection bits
; CONFIG FOSC = RC ;111X External RC oscillator, CLKOUT function on RA6
; CONFIG FOSC = ECLPIO6 ;EC oscillator (low power, <500 kHz)
; CONFIG FOSC = ECLP ;EC oscillator, CLKOUT function on OSC2 (low power, <500 kHz)
; CONFIG FOSC = ECMPIO6 ;EC oscillator (medium power, 500 kHz-16 MHz)
; CONFIG FOSC = ECMP ;EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
; CONFIG FOSC = INTIO7 ;Internal oscillator block, CLKOUT function on OSC2
; CONFIG FOSC = INTIO67 ;Internal oscillator block
; CONFIG FOSC = RCIO6 ;External RC oscillator
; CONFIG FOSC = RC ;External RC oscillator, CLKOUT function on OSC2
; CONFIG FOSC = ECHPIO6 ;EC oscillator (high power, >16 MHz)
; CONFIG FOSC = ECHP ;EC oscillator, CLKOUT function on OSC2 (high power, >16 MHz)
; CONFIG FOSC = HSMP ;HS oscillator (medium power 4-16 MHz)
; CONFIG FOSC = HSHP ;HS oscillator (high power > 16 MHz)
; CONFIG FOSC = XT ;XT oscillator
; CONFIG FOSC = LP ;LP oscillator
;*--------------------------------------------------------------------------------------------------------|
;* | -------------------------- | |
;* ----------------------------- | [PROTECTED OPTION FUSES] | ------------------------------------ |
;* | -------------------------- | |
;*--------------------------------------------------------------------------------------------------------|
CONFIG CP0 = OFF ; Block 0 (000800-003FFFh) not code-protected
CONFIG CP1 = OFF ; Block 1 (004000-007FFFh) not code-protected
CONFIG CP2 = OFF ; Block 2 (008000-00BFFFh) not code-protected
CONFIG CP3 = OFF ; Block 3 (00C000-00FFFFh) not code-protected
CONFIG CPB = OFF ; Boot block (000000-0007FFh) not code-protected
CONFIG CPD = OFF ; Data EEPROM not code-protected
CONFIG WRT0 = OFF ; Block 0 (000800-003FFFh) not write-protected
CONFIG WRT1 = OFF ; Block 1 (004000-007FFFh) not write-protected
CONFIG WRT2 = OFF ; Block 2 (008000-00BFFFh) not write-protected
CONFIG WRT3 = OFF ; Block 3 (00C000-00FFFFh) not write-protected
CONFIG WRTC = OFF ; Configuration registers (300000-3000FFh) not write-protected
CONFIG WRTB = OFF ; Boot Block (000000-0007FFh) not write-protected
CONFIG WRTD = OFF ; Data EEPROM not write-protected
CONFIG EBTR0 = OFF ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
CONFIG EBTR1 = OFF ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
CONFIG EBTR2 = OFF ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
CONFIG EBTR3 = OFF ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
CONFIG EBTRB = OFF ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
#ENDCONFIG
;*---------------------------------------------------------------------------------------------------------|
;*---------------------------------------------------------------------------------------------------------|
define OSC 64
INCLUDE "modedefs.bas"
INCLUDE"ALLDIGITAL.pbp"
OSCCON = %01110000 ; 64Mhz
OSCTUNE.6 = 1 ; Enable 4x PLL
while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code
'------------------------------------------------------------------------------|
' INITIALIZE RAM |
'------------------------------------------------------------------------------|
initialize:
CLEAR
'-------------------------------------------------------------------------------------------------------------------------------------------------------------
TRISA = %00000000 'use TRISA to specify which pin is (1 = input) and which (0 = output) (ALL pins are output)
TRISB = %10000000 'use TRISB to specify which pin is (1 = input) and which (0 = output) (RB7 PORTB.7 is the RX input pin of the EUART, the rest are output)
TRISC = %00000000 'use TRISC to specify which pin is (1 = input) and which (0 = output) (RC7 PORTC.7 is the RX input pin of the EUART, the rest are output)
'in PORTC the RC3 attached is an LED.
'------------------------------------------------------------------------|
'--------------------------- TRIS A B C ---------------------------------|
'------------------------------------------------------------------------|
' PORTA.7 PORTA.6 PORTA.5 PORTA.4 PORTA.3 PORTA.2 PORTA.1 PORTA.0 |
' bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 |
' 0 0 0 0 0 0 0 0 |
'------------------------------------------------------------------------|
'------------------------------------------------------------------------|
' PORTB.7 PORTB.6 PORTB.5 PORTB.4 PORTB.3 PORTB.2 PORTB.1 PORTB.0 |
' bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 |
' 1 0 0 0 0 0 0 0 |
'------------------------------------------------------------------------|
'------------------------------------------------------------------------|
' PORTC.7 PORTC.6 PORTC.5 PORTC.4 PORTC.3 PORTC.2 PORTC.1 PORTC.0 |
' bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 |
' 1 0 0 0 0 0 0 0 |
'------------------------------------------------------------------------|
'------------------------------------------------------------------------|
'----------------------- At start all PORTS LOW -------------------------|
'------------------------------------------------------------------------|
PORTA = 0 'make low all ports at A range |
PORTB = 0 'make low all ports at B range |
PORTC = 0 'make low all ports at C range |
PORTE = 0 'make low all ports at E range |
'------------------------------------------------------------------------|
'------------------------------------------------------------------------|
'-------------------------- COMPARATORS OFF -----------------------------|
'------------------------------------------------------------------------|
CM1CON0.7 = 0 'Disable comparator1 |
CM2CON0.7 = 0 'Disable comparator2 |
'------------------------------------------------------------------------|
'*-----------------------------------------------------------------------------|
'* | --------------------- | |
'*----------------------- | EUART 1 Configuration | ---------------------------|
'* | --------------------- | |
'*-----------------------------------------------------------------------------|
'RCSTA = $90 ' Enable serial port & continuous receive
'TXSTA = $24 ' Enable transmit, BRGH = 1
'DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'SPBRG = 130 ' 9600 Baud @ 64MHz, -0,02%
'SPBRGH = 6
'BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
'BAUDCON.5 = 1
'BAUDCON = %10001000
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 138 ' 115200 Baud @ 64MHz, -0,08%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
'*-----------------------------------------------------------------------------|
'* | --------------------- | |
'*----------------------- | EUART 2 Configuration | ---------------------------|
'* | --------------------- | |
'*-----------------------------------------------------------------------------|
DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
DEFINE HSER2_SPBRG 160 ' 38400 Baud @ 64MHz, -0,08%
SPBRGH2 = 1
BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator
'*-----------------------------------------------------------------------------|
'*-----------------------------------------------------------------------------|
PWRLED var PORTA.0 ' indicates that PIC is working on port C.4
'------------------------------------------------------------------------------|
' FONTS FROM THE uSD |
'------------------------------------------------------------------------------|
'file_LoadImageControl[0009 "FONTST~2.d01" "FONTST~2.g01" 0001] 0,033 (ACK 5148 0x141C)
'file_LoadImageControl[0009 "FONTST~2.d02" "FONTST~2.g02" 0001] 0,038 (ACK 4845 0x12ED)
'file_LoadImageControl[0009 "FONTST~2.d03" "FONTST~2.g03" 0001] 0,037 (ACK 4542 0x11BE)
'file_LoadImageControl[0009 "FONTST~2.d04" "FONTST~2.g04" 0001] 0,039 (ACK 4239 0x108F)
'file_LoadImageControl[0009 "FONTST~2.d05" "FONTST~2.g05" 0001] 0,042 (ACK 3936 0x0F60)
'file_LoadImageControl[0009 "FONTST~2.d06" "FONTST~2.g06" 0001] 0,038 (ACK 3633 0x0E31)
'file_LoadImageControl[0009 "FONTST~2.d07" "FONTST~2.g07" 0001] 0,040 (ACK 3330 0x0D02)
'file_LoadImageControl[0009 "FONTST~2.d08" "FONTST~2.g08" 0001] 0,045 (ACK 3027 0x0BD3)
' -----------------------------------------------------------------------------|
' [ LCD Initialization ] |
'------------------------------------------------------------------------------|
' FIRST TIME BOOTUP: We give plenty of time for tbe LCD '
pause 3000
high pwrled
HSerout2[$FF,$9E,$00,$01] 'SPE serial graphic interface -SET THE LANDSCAPE R
Hserin2 [wait(6)]
HSEROUT2 [$FF,$03] ' MOUNT FILE, this is very imporntat command in here.
Hserin2 [wait(6)]
'HSEROUT2[$00,$09,"FONTST~2.d07","FONTST~2.g07",$00,$01] ' SPE serial graphic interface - CALL FONT from SD
'Hserin2 [wait(6)]
HSEROUT2 [$FF,$00,$00,$46] ' SOUND VOLUME to 70
Hserin2 [wait(6)]
Pause 100
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$7F] ' SPE serial graphic interface - SET COLOR (CYAN)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$01,$00,$02] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
pause 100
hserout2[$00,$18,"Leonardo Bilalis",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$F8,$00] ' SPE serial graphic interface - SET COLOR (RED)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$03,$00,$03] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
pause 100
hserout2[$00,$18,"Copyright 2018",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$05,$00,$05] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$E0] ' SPE serial graphic interface - SET COLOR (YELLOW)
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
pause 100
hserout2[$00,$18,"GPS SYSTEM",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$07,$00,$03] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$01] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$01] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$E0] ' SPE serial graphic interface - SET COLOR (LIME)
Hserin2 [wait(6)]
hserout2[$00,$18,"G",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"P",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"S",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18," M",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"K",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"T",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18," 3",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"3",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"3",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"9",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18," a",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"n",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"d",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18," P",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"I",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"C",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"1",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"8",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"F",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"2",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"6",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"K",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"2",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
HSEROUT2 [$00,$0B,"SOUND.WAV",$00]
'HSEROUT2 [$00,$0B,"LASER2.WAV",$00]
Hserin2 [wait(6)]
hserout2[$00,$18,"2",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
pause 3000
HSEROUT2 [$FF,$CD] ' clear the LCD
Hserin2 [wait(6)]
'------------------------------------------------------------------------------|
' [ GPS HOLD ON RESET for a bit ] |
'------------------------------------------------------------------------------|
high portc.3 ' we set high the ENABLE pin at GPS |
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$E0] ' SPE serial graphic interface - SET COLOR (LIME)
Hserin2 [wait(6)]
'HSEROUT2[$FF,$DE,$00,$01] ' SPE serial graphic interface - SETO BOLD
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$01,$00,$00] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
hserout2[$00,$18,"Powering up the GPS",$00] 'SPE serial graphic interface - PUT STRING
Hserin2 [wait(6)]
' -----------------------------------------------------------------------------|
' [ GPS Initialization ] |
'------------------------------------------------------------------------------|
' When the GPS Module is POWERED ON, then the following sentenses are received.
HSERIN [wait("PMTK011,MTKGPS*08")]
HSERIN [wait("PMTK010,001*2E")]
HSERIN [wait("PMTK010,002*2D")]
HSEROUT2[$FF,$E9,$00,$03,$00,$03] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$F8,$00] ' SPE serial graphic interface - SET COLOR (RED)
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"GPS is ENABLED",$00]
Hserin2 [wait(6)]
pause 1500
'------------------------------------------------------------------------------|
' Changing Baudrate and Frequency |
'------------------------------------------------------------------------------|
HSEROUT ["$PMTK314,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28",13,10]
'HSEROUT["$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0*29",13,10] ' ZDA ONLY
pause 100
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$01] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$01] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$FF] ' SPE serial graphic interface - SET COLOR (WHITE)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$0C,$00,$02] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
hserout2[$00,$18,"NMEA:",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$0F,$00,$01] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$7F] ' SPE serial graphic interface - SET COLOR (CYAN)
Hserin2 [wait(6)]
hserout2[$00,$18,"RMC+VTG",$00]
Hserin2 [wait(6)]
'HSEROUT["$PMTK251,38400*27",13,10] ' 38400 boundrate, check MTK manual configuration
'pause 100
'HSEROUT2[$FF,$E9,$00,$0C,$00,$0F] ' SPE serial graphic interface - SET Y,X position
'Hserin2 [wait(6)]
'HSEROUT2[$FF,$E7,$FF,$FF] ' SPE serial graphic interface - SET COLOR (WHITE)
'Hserin2 [wait(6)]
'hserout2[$00,$18,"Baudrate:",$00]
'Hserin2 [wait(6)]
'HSEROUT2[$FF,$E9,$00,$0F,$00,$0F] ' SPE serial graphic interface - SET Y,X position
'Hserin2 [wait(6)]
'HSEROUT2[$FF,$E7,$07,$7F] ' SPE serial graphic interface - SET COLOR (CYAN)
'Hserin2 [wait(6)]
'hserout2[$00,$18,"38400 bps",$00]
'Hserin2 [wait(6)]
'SPBRG = 160 ' 38400 Baud @ 64MHz, -0,08%
'SPBRG2 = 21 ' 57600 Baud @ 64MHz, -0,08%
'SPBRG2 = 138 ' 115200 Baud @ 64MHz, -0,08%
'SPBRGH = 1
HSEROUt["$PMTK220,100*2F",13,10] ' 100(millisecond)=0.1(sec)-->1/0.1= 10Hz
pause 100
HSEROUT2[$FF,$E9,$00,$0C,$00,$1B] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$FF] ' SPE serial graphic interface - SET COLOR (WHITE)
Hserin2 [wait(6)]
hserout2 [$00,$18,"Refresh Rate:",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$0F,$00,$20] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$7F] ' SPE serial graphic interface - SET COLOR (CYAN)
Hserin2 [wait(6)]
hserout2 [$00,$18,"10Hz",$00]
Hserin2 [wait(6)]
pause 3000
HSEROUT2 [$FF,$CD] ' clears the LCD
Hserin2 [wait(6)]
'*-----------------------------------------------------------------------------|
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
day var byte 'day
month var byte 'month
year var byte 'year
SPEED var word 'speed with conversion ASCII to dec -48
Km var byte 'this is a letter K --> KM/H om the GPVTG sentence
TS var byte[4] 'TOTAL SPEED. we create an array to combine each possible character for speed
decimal var byte
i var word 'we use this for Total speed point
FIX var byte 'fix sat V/A
Modefix var byte 'mode fix 1 or 2 or 3 depens
Day_added var byte
Numofdays var byte 'these are the days of each months
LeapYear var byte 'this is a year leap
ndays var byte[13]'create an array with 13 byte location for Months values
mode2d3d var byte
RED var PORTA.3
GREEN var PORTA.2
BLUE VAR PORTA.1
'--------------------------------------------------------------------------------|
' |
' ---------------------------- [ MAIN ] ----------------------------------- |
' |
'--------------------------------------------------------------------------------|
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
HSERIN timeout,lostcable,[wait("$GNRMC"),_ ;we wait for $GPRMC
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(","),dec3 degrees2,dec2 minutes2,wait("."),dec4 minutesd2,_;we wait for 02353.3600
wait(","),dir2,_ ;we wait for E/W
wait(","),wait(","),_
wait(","),dec2 day,dec2 month,dec2 year,_ ;we wait for 170518
wait(","),SKIP 3]
'------------------------------------------------------------------------------/
' /
' [ 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
HSERIN timeout,lostcable,[wait("$GNGGA"),_ ;we wait for GPGGA
wait(","),skip 41,_
wait(","),dec2 satno,_
wait(","),skip 19]
'wait(","),modefix,_ ;we wait for modefix 1,2 or 3 check gps manual for NMEA
'------------------------------------------------------------------------------/
' /
' [ Example NMEA Sentense of GPGSA ] /
' [$GPGSA,A,3,18,08,10,11,14,27,22,32,01,,,,2.62,1.11,2.37*03] /
' /
'-------------------------------------------------------------------------/
HSERIN timeout,lostcable,[wait("$GPGSA"),wait(","),wait(","),mode2d3d,wait(","),SKIP 50]
if fix = "V" then gps
'serin2 gps_tx,84,timeout,lostcable,[wait("GNVTG"),_
HSERIN timeout,lostcable,[wait("GNVTG"),wait("N"),_
wait(","),TS[0],TS[1],TS[2],TS[3],TS[4],_
wait(","),SKIP 3]
for i = 1 to 3
if TS[i]="." then decimal = i 'TOTAL SPEED. find which character is the decimal point at ulcd fort is the ":"
next i
select case decimal 'if the gps shows 1.45 it may be 145
'for the conversion ASCII to number we can use the -48
case 1 'decimal position is x.xx
SPEED = (10*(TS[0]-48))+(TS[2]-48)
case 2 'decimal position is xx.xx
SPEED = (100*(TS[0]-48))+(10*(TS[1]-48))+(TS[3]-48)
case 3 'decimal position is xxx.xx
SPEED = (1000*(TS[0]-48))+(100*(TS[1]-48))+(10*(TS[2]-48))
end select
gosub OVERSPEED
'-----------------------------------------------------------------------------/
' Here we start the calendar conversion /
'---------------------------------------------------------------------------/
arraywrite ndays,13,NDAY,[0,31,28,31,30,31,30,31,31,30,31,30,31]
if ndays = 2 then
if ((year//4 = 0) and (year//400 != 0)) then 'check the leap year
ndays[2] = 29 'then February has 29 days
else
ndays[2] = 28 'else has 28 days
endif
endif
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 = day + 1 'we check the day added is true
hh = hh//24 'but the hour not exceed the 24 so go to 00:00
if (day > ndays[month]) then
month = month + 1
day = 1
if (month > 12) then
year = year + 1
month = 1
endif
endif
endif
'--------------------------------------------------------------------------/
' here is where the code dispays the stored info from the NMEA sentenses /
'------------------------------------------------------------------------/
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$FF] ' SPE serial graphic interface - SET COLOR (WHITE)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$02,$00,$04] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"GROUND SPEED",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$06,$00,$08] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"Km/h",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$E0] ' SPE serial graphic interface - SET COLOR (LIME)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$05] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$06] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$01,$00,$02] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,TS[0],TS[1],TS[2],TS[3],$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$E0] ' SPE serial graphic interface - SET COLOR (Yellow)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$00,$00,$00] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,dec2 hh,":",dec2 mm,":",dec2 ss,$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$E0] ' SPE serial graphic interface - SET COLOR (Yellow)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$00,$00,$0C] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,dec2 day,"/",dec2 month,"/",dec2 year,$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$F8,$00] ' SPE serial graphic interface - SET COLOR (RED)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$04,$00,$00] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"Sats",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2[$FF,$E7,$07,$FF] ' SPE serial graphic interface - SET COLOR (AQUA)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$05,$00,$01] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,dec2 satno,$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2[$FF,$E7,$F8,$00] ' SPE serial graphic interface - SET COLOR (RED)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$04,$00,$11] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"Fix",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2[$FF,$E7,$07,$FF] ' SPE serial graphic interface - SET COLOR (AQUA)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$05,$00,$011] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,fix,mode2d3d,"D",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2[$FF,$E7,$F8,$00] ' SPE serial graphic interface - SET COLOR (RED)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$08,$00,$01] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$00,$18,"Lat:",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2[$FF,$E7,$FF,$E0] ' SPE serial graphic interface - SET COLOR (Yellow)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$08,$00,$06] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$00,$18,dec2 degrees,"°",dec2 minutes,".",dec4 minutesd,"'"," ",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$E0] ' SPE serial graphic interface - SET COLOR (LIME)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$08,$00,$11] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$00,$18,dir,$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$F8,$00] ' SPE serial graphic interface - SET COLOR (RED)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$09,$00,$01] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$00,$18,"Lon:",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$E0] ' SPE serial graphic interface - SET COLOR (Yellow)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$09,$00,$05] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$00,$18,dec3 degrees2,"°",dec2 minutes2,".",dec4 minutesd2,"'"," ",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$07,$FF] ' SPE serial graphic interface - SET COLOR (CYAN)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$09,$00,$11] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$00,$18,dir2,$00]
Hserin2 [wait(6)]
goto main
'-----------------------------------------------------------------------------/
' [ SUB ROUTINES ] /
'---------------------------------------------------------------------------/
OVERSPEED:
if SPEED > 1000 then ' 100Km/h
high BLUE
low GREEN
low RED
else
LOW BLUE
if SPEED > 500 then ' 50Km/h
high GREEN
low RED
else
LOW GREEN
if SPEED > 100 then ' 10Km/h
high RED
else
LOW RED
endif
endif
endif
return
GPS:
HSEROUT2 [$FF,$CD] ' clear the LCD
Hserin2 [wait(6)]
hh = hh + 3
hh = hh//24
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$FF] ' SPE serial graphic interface - SET COLOR (WHITE)
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$01,$00,$05] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"PLEASE WAIT",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$04,$00,$09] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"GPS",$00]
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$06,$00,$06] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"NOT FIXED",$00]
Hserin2 [wait(6)]
pause 3000
HSEROUT2 [$FF,$CD] ' clear the LCD
Hserin2 [wait(6)]
goto main 'returns to main
'-----------------------------------------------------------------------------/
' [ Connection lost Please check the GPS ] /
'---------------------------------------------------------------------------/
lostcable:
HSEROUT2 [$FF,$CD] ' clear the LCD
Hserin2 [wait(6)]
HSEROUT2[$FF,$E5,$00,$02] ' SPE serial graphic interface - SET FONT
Hserin2 [wait(6)]
HSEROUT2[$FF,$E4,$00,$02] 'SPE serial graphic interface - SET WIDTH of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E3,$00,$02] ' SPE serial graphic interface - SET HEIGHT of the text
Hserin2 [wait(6)]
HSEROUT2[$FF,$E9,$00,$02,$00,$02] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$F8,$00] ' SPE serial graphic interface - SET COLOR (RED)
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"Connection lost",$00]
Hserin2 timeout,lostcable,[wait(6)]
HSEROUT2[$FF,$E9,$00,$04,$00,$01] ' SPE serial graphic interface - SET Y,X position
Hserin2 [wait(6)]
HSEROUT2[$FF,$E7,$FF,$E0] ' SPE serial graphic interface - SET COLOR (YELLOW)
Hserin2 [wait(6)]
HSEROUT2 [$00,$18,"Please check cable",$00]
Hserin2 timeout,lostcable,[wait(6)]
pause 2000
HSEROUT2 [$FF,$CD] ' clear the LCD
Hserin2 [wait(6)]
goto main
'-----------------------------------------------------------------------------/
' [ Calendar days in Months ] /
'---------------------------------------------------------------------------/
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
Bookmarks