'**************************************************************** '* Name : GPSchecker.BAS * '* Author : John Drew VK5DJ * '* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 25/04/2009 * '* Version : 1.0 * '* Notes : written for Chris VK5MC to indicate GPS lock * '* : for his GPS derived frequency standard. * '* : The code is written for a single line display that* '* : requires the second 8 chars to be treated as a * '* : new line. See the print statements in "MAIN". * '* : Anyone copying this design will need to adjust * '* : the print statements if they use a different LCD. * '**************************************************************** Device 16F628A Declare Xtal 8 All_Digital=true Declare LCD_Type 0 ' text type Declare LCD_DTPin PORTB.4 ' assigns data lines to B4..7 Declare LCD_ENPin PORTB.0 ' enable pin Declare LCD_RSPin PORTB.3 ' RS line pin Declare LCD_Interface 4 ' 4 or 8 line interface Declare LCD_Lines 2 ' lines in the display Declare LCD_DataUs 255 ' delay data to allow for slow LCD 'set up the serial port Hserial_Baud = 4800 ' Set baud rate to 4800 Hserial_RCSTA = %10010000 ' Enable serial port and continuous receive Hserial_TXSTA = %00000000 ' TX disabled Hserial_Clear = On ' Optionally clear the buffer before receiving Dim Hour As Byte ' time variables Dim Minute As Byte Dim Second As Byte Dim Time As Dword Dim Quality As Byte ' 1=no fix, 2 = 2d fix, 3 = 3d fix Dim ValueA As Byte ' a validity check, currently unused TRISB=%00000010 ' (outputs) RB0, RB2-7 ' (inputs) RB1 TRISA=%11110001 ' Configure RA Symbol LockLed2D = PORTA.1 ' 2d lock only Symbol NoLockled = PORTA.2 ' no lock ring buzzer Symbol LockLed3D = PORTA.3 ' Lock LED normally on receiving 3D data GoTo Initialise ExtractTime: Second = Time // 100 ' extract the components of time from a Dword Time = Time / 100 Minute = Time // 100 Hour = Time / 100 Return BringInGPS: HRSIn Wait ("$GPRMC,"), Dec Time ' get the time from the $GPRMC string GoSub ExtractTime ' dismantle the Dword time HRSIn Wait ("$GPGSA,"), ValueA, Dec Quality ' get the quality from the $GPGSA string Return Initialise: Quality = 0 'ensure a clean start Second = 0 Minute = 0 Hour = 0 Clear NoLockled Clear LockLed3D Clear LockLed2D Cls Print At 1,1,"GPS wait" DelayMS 1000 Main: GoSub BringInGPS If Hour<10 Then Print At 1,1,"0", Dec Hour, ":" ' insert a 0 if necessary Else Print At 1,1, Dec Hour, ":" EndIf If Minute<10 Then ' insert a 0 if necessary Print "0", Dec Minute, ":" Else Print Dec Minute, ":" EndIf If Second<10 Then ' insert a 0 if necessary Print "0", Dec Second, " " Else Print Dec Second, " " EndIf If Quality <2 Or Quality > 3 Then ' test for absence of GPS lock Print At 2,1, " UTC-no " Set NoLockled Clear LockLed3D Clear LockLed2D EndIf If Quality = 2 Then ' 2D lock only Print At 2,1, " UTC-2D " Clear NoLockled Clear LockLed3D Set LockLed2D EndIf If Quality = 3 Then ' full lock achieved Print At 2,1, " UTC-3D " Clear NoLockled Set LockLed3D Clear LockLed2D EndIf GoTo Main End