' ========================================================================= ' ' GPS Receiver & Serial LCD ' ' ------------------------------------------------------------------ ' ' File - GPS2.BAS ' Author - Joe Caldwell ' Updated - 15 SEPT 2007 (modified from below project for use with PIC instead of Basic Stamp 2) ' Updated - 16 SEPT 2007 (modified to add satellite acquisition indication) ' '========================================================================== ' MAKE Magazine Video Podcast: Weekend Projects Special Edition ' Awesome Electronics Workshop w/ Joe Grand & Bre Pettis ' ' GPS Receiver & Serial LCD ' ' ------------------------------------------------------------------ ' ' File...... GPS_LCD.bs2 ' Author.... Joe Grand (Grand Idea Studio, www.grandideastudio.com) ' Updated... 13 FEB 2007 ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' Retreives GPS coordinates from the Parallax GPS Receiver module and ' displays them on a 2 line x 16 character Serial LCD module. Perfect for ' geocaching! ' ' Before running this demo, ensure that the /RAW pin is left unconnected ' or pulled HIGH to enable "smart" mode, in which the GPS Receiver Module ' will accept commands and return the requested GPS data. ' ' -----[ I/O Definitions ]------------------------------------------------- LCD_TX CON 0 ' serial output to LCD GPS_SIO CON 1 ' connects to GPS Module SIO pin ' -----[ Constants ]------------------------------------------------------- '---- [LCD Constants] ---- LcdBaud CON 84 'mode LcdBaud corresponds to 9600 Baud LcdBkSpc CON $08 ' move cursor left LcdRt CON $09 ' move cursor right LcdLF CON $0A ' move cursor down 1 line LcdCls CON $0C ' clear LCD (use PAUSE 5 after) LcdCR CON $0D ' move pos 0 of next line LcdBLon CON $11 ' backlight on LcdBLoff CON $12 ' backlight off LcdOff CON $15 ' LCD off LcdOn1 CON $16 ' LCD on; cursor off, blink off LcdOn2 CON $17 ' LCD on; cursor off, blink on LcdOn3 CON $18 ' LCD on; cursor on, blink off LcdOn4 CON $19 ' LCD on; cursor on, blink on LcdLine1 CON $80 ' move to line 1, column 0 LcdLine2 CON $94 ' move to line 2, column 0 LcdCC0 CON $F8 ' define custom char 0 LcdCC1 CON $F9 ' define custom char 1 LcdCC2 CON $FA ' define custom char 2 LcdCC3 CON $FB ' define custom char 3 LcdCC4 CON $FC ' define custom char 4 LcdCC5 CON $FD ' define custom char 5 LcdCC6 CON $FE ' define custom char 6 LcdCC7 CON $FF ' define custom char 7 DispCC0 CON $00 ' display custom char 0 '---- [GPS Constants] ---- GPSBaud CON 188 'mode 188 corresponds to 4800 Baud DegSym CON 176 ' degrees symbol for report MinSym CON 39 ' minutes symbol SecSym CON 34 ' seconds symbol ' GPS Module Commands GetInfo CON $00 GetValid CON $01 GetSats CON $02 GetTime CON $03 GetDate CON $04 GetLat CON $05 GetLong CON $06 GetAlt CON $07 GetSpeed CON $08 GetHead CON $09 ' -----[ Variables ]------------------------------------------------------- degrees VAR BYTE ' latitude degrees/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) sats VAR BYTE temp VAR WORD ' for numeric conversions char VAR BYTE ' -----[ EEPROM Data ]----------------------------------------------------- ' C#---- Data---------------------------------- CC0 DATA LcdCC0, $08, $14, $08, $00, $00, $00, $00, $00 ' degree symbol ' -----[ Initialization ]-------------------------------------------------- Reset: HIGH LCD_TX ' setup serial output pin PAUSE 100 ' allow LCD to initialize DnLoad_Custom_Chars: FOR temp = 0 TO 8 ' download custom characters READ CC0 + temp, char ' get data from table serout2 LCD_TX, LcdBaud, [char] ' send to LCD NEXT serout2 LCD_TX, LcdBaud, [LcdBLoff, LcdOn1, LcdCls] PAUSE 250 serout2 LCD_TX, LcdBaud, [LcdBLon] ' turn backlight on (only works with backlit serial LCD module) ' -----[ Program Code ]---------------------------------------------------- SAT: ' get satellite data from GPS serout2 GPS_SIO, GPSBaud, ["!GPS", GetSats] serin2 GPS_SIO, GPSBaud, 3000, No_Response, [sats] ' check if GPS has found at least 3 satellites IF sats < 3 THEN serout2 LCD_TX, LcdBaud, [LcdCls, LcdLine1, "Searching for"] serout2 LCD_TX, LcdBaud, [LcdLine2, "satellites..."] PAUSE 1000 GOTO SAT IF sats > 3 THEN GPS ENDIF GPS: ' get latitude from GPS serout2 GPS_SIO, GPSBaud, ["!GPS", GetLat] SERIN2 GPS_SIO, GPSBaud, 3000, No_Response, [degrees, minutes, minutesD.HIGHBYTE, minutesD.LOWBYTE, dir] ' convert decimal minutes to tenths of seconds temp = minutesD ** $0F5C ' minutesD * 0.06 ' display latitude on LCD line 1 serout2 LCD_TX, LcdBaud, [LcdLine1, DEC3 degrees, DispCC0, " ", DEC2 minutes, MinSym, " "] serout2 LCD_TX, LcdBaud, [DEC2 (temp / 10), ".", DEC1 (temp // 10), SecSym, " ", "N" + (dir * 5)] ' get longitude from GPS serout2 GPS_SIO, GPSBaud, ["!GPS", GetLong] SERIN2 GPS_SIO, GPSBaud, 3000, No_Response, [degrees, minutes, minutesD.HIGHBYTE, minutesD.LOWBYTE, dir] ' convert decimal minutes to tenths of seconds temp = minutesD ** $0F5C ' minutesD * 0.06 ' display longitude on LCD line 2 serout2 LCD_TX, LcdBaud, [LcdLine2, DEC3 degrees, DispCC0, " ", DEC2 minutes, MinSym, " "] serout2 LCD_TX, LcdBaud, [DEC2 (temp / 10), ".", DEC1 (temp // 10), SecSym, " ", "E" + (dir * 18)] PAUSE 1000 ' wait 1 second, then do it all again GOTO SAT END ' -----[ Subroutines ]----------------------------------------------------- No_Response: serout2 LCD_TX, LcdBaud, [LcdCls, LcdLine1, "Error: GPS"] serout2 LCD_TX, LcdBaud, [LcdLine2, "Receiver Module"] PAUSE 5000 GOTO SAT