'18LF4520 8MHz x4 5110 NEO8 SML 050118 1400 Define CONFIG1L = 0x00 Define CONFIG1H = 0x08 'INT OSC Define CONFIG2L = 0x1e Define CONFIG2H = 0x00 Define CONFIG3L = 0x00 Define CONFIG3H = 0x80 'Set for HVP Define CONFIG4L = 0x80 Define CONFIG4H = 0x00 Define CONFIG5L = 0x0f Define CONFIG5H = 0xc0 Define CONFIG6L = 0x0f Define CONFIG6H = 0xe0 Define CONFIG7L = 0x0f Define CONFIG7H = 0x40 ''Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC Define CLOCK_FREQUENCY = 8 Define SINGLE_DECIMAL_PLACES = 2 Define STRING_MAX_LENGTH = 40 'Needs raising to fit the whole NMEA sentence for transmit>>>>>>>>>> AllDigital 'SET PIN IN/OUT TRISA = %00000001 TRISB = %00000000 TRISC = %10010000 '7=RX=1 4=SDI=1 1=RST=0 TRISD = %00000000 TRISE = %00000001 '1=Button 'SET BITS ON/OFF PORTA = %00000000 'ON/OFF PORTB = %00000000 PORTC = %00000000 PORTD = %00000000 PORTE = %00000000 'POSS MCLR RE3 ADCON0 = 0x03 'AN0-1-2-3 Can be used as Analogue inputs. ADCON1 = 0x0e ADCON2 = %10100100 PIR1 = 0 PIR2 = 0 PIE1 = 0 PIE2 = 0 PIE1.RCIE = 1 'rxd Intr , used for GPS serial input work IPR1 = 0 IPR2 = 0 RCON.IPEN = 1 'this MUST be included when using Interrupts OSCCON = %01110010 'internal 8Mhz clock OSCTUNE.PLLEN = 1 '*4 PLL enabled so Fosc = 32MHZ WaitMs 10 'SPI Define SPI_CS_REG = PORTD Define SPI_CS_BIT = 4 Define SPI_SCK_REG = PORTC Define SPI_SCK_BIT = 3 Define SPI_SDI_REG = PORTC 'not used, but left in so OSH does not burp Define SPI_SDI_BIT = 4 Define SPI_SDO_REG = PORTC Define SPI_SDO_BIT = 5 Symbol lcd_reset = PORTC.1 Symbol lcd_mode = PORTC.0 '1=DATA ,0=COMMAND Dim msg1 As String 'any msg data will be passed via this string Dim ascval As String Dim x As Byte Dim y As Byte Dim row As Byte 'lcd row pointer Dim xp As Byte 'normal font horiz Dim yp As Byte 'vert lcd location Dim str1(80) As Byte 'GPGGA STR1 ARRAY Dim strchr As String 'GPGGA msg Dim csv As Byte 'COMMA POSITION in GPS msg Dim strlat As String Dim strlong As String Dim stralt As String Dim strtim As String Dim sinlat As Single Dim sinlong As Single Dim sinalt As Single Dim char As Byte Dim rxi As Byte Dim txi As Byte Dim binval As Single Disable High Disable Low Include "fontsml.bas" 'This 'FONT' file nust be in the same folder as this program code Include "get_neo.bas" 'This 'GPS' file nust be in the same folder as this program code msg1 = "" Hseropen 9600 Hserout "Ready!", CrLf start: 'do a lcd Reset Gosub rst_lcd '5110 states very early RESET is important SPIPrepare Gosub cmd5110 'init lcd WaitMs 10 Call clear() main: 'GPS' Gosub get_neo 'Reads NMEA DATA End 'this subr extracts the main values from the GPS string, into named value messages 'also converts the string to a named numeric value, for maths 'NOTE: hserouts for demo test only get_val: Select Case csv 'Comma separated values Case 1 Case 2 strtim = LeftStr(msg1, 2) + ":" + MidStr(msg1, 3, 2) + ":" + MidStr(msg1, 5, 2) Case 3 strlat = LeftStr(msg1, 8) sinlat = StrValS(strlat) Case 5 strlong = RightStr(msg1, 8) sinlong = StrValS(strlong) Case 12 stralt = msg1 sinalt = StrValS(stralt) Case Else EndSelect msg1 = "" Return ''writes the msg To the lcd at xp [column] And yp {row] [WRITES SMALL DIGITS] Proc wr_msg(xp As Byte, yp As Byte, msg1 As String) lcd_mode = 0 'cmd xp = xp * 6 xp = 0x80 Or xp yp = 0x40 Or yp SPICSOn SPISend xp SPISend yp SPICSOff lcd_mode = 1 'data y = Len(msg1) For x = 1 To y ascval = MidStr(msg1, x, 1) Gosub chr2lcd 'in fontsml.bas Next x End Proc Proc clear() For yp = 0 To 5 Call clr_row(yp) Next yp End Proc 'clears all normal font row xp Proc clr_row(yp As Byte) xp = 0 lcd_mode = 0 xp = xp * 6 xp = 0x80 Or xp yp = 0x40 Or yp SPICSOn SPISend xp SPISend yp SPICSOff lcd_mode = 1 SPICSOn For x = 0 To 83 'all pixels across SPISend 0x00 Next x SPICSOff End Proc 'initialise 5110 and set lcd writing direction cmd5110: lcd_reset = 0 WaitMs 100 lcd_reset = 1 WaitMs 10 lcd_mode = 0 'cmd mode WaitMs 10 SPICSOn SPISend 0x21 WaitUs 100 SPISend 0xb1 'b8 contrast was b0Set LCD Vop 0xB0 for 5V, 0XB1 for 3.3v, 0XBF if screen too dark] WaitUs 100 SPISend 0x04 WaitUs 100 SPISend 0x14 'lcd bias WaitUs 100 SPISend 0x20 WaitUs 100 SPISend 0x0c '' 09 now normal data write mode WaitUs 100 SPICSOff 'this is for setting top left of lcd and bit write direction. lcd_mode = 0 xp = xp * 6 xp = 0x80 Or xp yp = 0x40 Or yp SPICSOn SPISend xp SPISend yp SPICSOff WaitMs 5 ''' Return ''gosubs vv Proc single2asc(arg1 As Single) msg1 = #arg1 End Proc Proc word2asc(arg1 As Word) msg1 = #arg1 End Proc Proc long2asc(arg1 As Long) msg1 = #arg1 End Proc 'reset the lcd rst_lcd: lcd_reset = 1 WaitMs 10 lcd_reset = 0 WaitMs 10 lcd_reset = 1 Return 'all four quadrants 'test1 '$GPGGA,123459.00,5001.00000,N,00059.00000,W,1,04,1.80,1.2,M,47.7,M,,*7F? 'test2 '$GPGGA,123459.00,4959.00000,N,00059.00000,W,1,04,1.80,250.0,M,47.7,M,,*7F? 'test3 '$GPGGA,123459.00,4959.00000,N,00101.00000,W,1,04,1.80,500.0,M,47.7,M,,*7F? 'test4 '$GPGGA,123459.00,5001.00000,N,00101.00000,W,1,04,1.80,1000.0,M,47.7,M,,*7F? 'fareham '$GPGGA,Fareham,5051.19000,N,00111.53200,W,1,04,1.80,100.0,M,47.7,M,,*7F? ''Putty examples '$GPTXT,01,01,02,u-blox ag - www.u-blox.com*? '$GPGGA,164803,,,,,1,04,1.80,,,47.7,M,,*77?