'18LF4520 8MHz 5110 NEO8 SML 281217 TEST Define CONFIG1L = 0x00 Define CONFIG1H = 0x08 'INT OSC Define CONFIG2L = 0x1e Define CONFIG2H = 0x00 Define CONFIG3L = 0x00 Define CONFIG3H = 0x80 Define CONFIG4L = 0x80 'Set for HVP 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 = 60 AllDigital Symbol pot = PORTA.0 'adc Symbol yled = PORTA.4 'yled Symbol rled = PORTA.5 'rled Symbol button = PORTE.0 button = 1 'TEMP REMOVE***************************************** '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 WaitMs 10 'START UP LEDS yled = 1 WaitMs 500 yled = 0 rled = 1 WaitMs 500 rled = 0 '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 [D/C] 'bin2asc buffers, NOTE: fixed location in memory Dim ascbfr4 As Byte Dim ascbfr3 As Byte Dim ascbfr2 As Byte Dim ascbfr1 As Byte Dim ascbfr0 As Byte Dim b2aval As Word Dim temp3 As Word Dim v0 As Word 'adco count Dim tot As Word 'demo count total Dim vlong As Long 'maths 'preloaded lcd/txd msgs Dim menu1 As String Dim menu2 As String Dim menu3 As String Dim menu4 As String Dim menu5 As String Dim menu6 As String Dim clearscn As String Dim msg1 As String 'any msg data will be passed via this string Dim msg2 As String Dim msgsize1 As Byte 'for MENU choice Dim msgsize2 As Byte 'for MENU choice Dim ascval As String Dim rxdchr As String Dim rxdmsg As String Dim rxdbyt As Byte 'RXD char Dim nmeatime As String 'EXTRACTED 'TIME' FROM NMEA GPS SENTENCE>>>>>>>>>>>>>>>>>>>>>>>>>>> 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 xx As Byte 'big font hor Dim yy As Byte 'vert Dim cnt As Byte 'demo number display count Dim cp As Byte Dim fp As Byte Dim h As Byte 'Horizontal position h = 0 'Horizontal position test Dim v As Byte 'Vertical position test v = 0 'Vertical position test Dim str1(70) As Byte 'STR1 ARRAY Dim strchr As String '++++++++++++++++++ Dim csv As Byte '+++++++++++++++++++ Dim strlat As String Dim strlong As String Dim stralt 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 ix As Byte 'NEW Include "font1.bas" 'this file nust be in the same folder as this program code 'test messages, your project msgs go here, more if needed 'test msgs, note: 14 characters/row And 6 rows with this fonts1.bas menu1 = "STRING TEST" 'SML MAX 60 BIG MAX 9 msg1 = "" Hseropen 9600 start: 'do a lcd Reset Gosub rst_lcd '5110 states very early RESET is important SPIPrepare Gosub cmd5110 'init lcd WaitMs 10 main: '''If button = 0 Then Gosub clearscreen '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GPS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ get_neo: ''$GPGGA,Test,5001.00000,N,00059.00000,W,1,04,1.80,1.2,M,47.7,M,,*7F? rxi = 0 If RCSTA.OERR = 1 Then 'RCSTA BIT1-if over run error then flush RXD buffer RCSTA.CREN = 0 RCSTA.CREN = 1 char = RCREG PIR1.RCIF = 0 Endif sync1: 'wait for a $ start of string If PIR1.RCIF = 0 Then Goto sync1 'PIR1 BIT5 char = RCREG If char <> 0x24 Then Goto sync1 '$' str1(1) = char 'STR1 ARRAY rxi = 2 getmsg: 'read and save GPGGA msg If PIR1.RCIF = 0 Then Goto getmsg char = RCREG str1(rxi) = char 'STR1 ARRAY rxi = rxi + 1 If rxi > 80 Then Goto get_neo 'msg bfr over run 'If char = 0x0a Then Goto eomsg 'LINE FEED COMMENT IN FOR PIC [AT END OF MSG STRING]&&&&&&&&&&&&&&&&&&&&& If char = 0x3f Then Goto eomsg '? COMMENT IN FOR SIM [AT END OF MSG STRING]&&&&&&&&&&&&&&&&&&&&&&& Goto getmsg If rxi < 60 Then 'invalid msg Goto get_neo Endif eomsg: 'echo back out the str1 data as a test only If str1(5) = 0x47 Then csv = 0 For txi = 1 To 90 char = str1(txi) strchr = Chr(char) If strchr <> "," Then msg1 = msg1 + strchr Else csv = csv + 1 Gosub get_val Endif Next txi Endif 'for demo ONLY Hserout "lat=", #sinlat, " lon=", #sinlong, " alt=", #sinalt, CrLf msg1 = "" Goto get_neo ''$GPGGA,test,5001.00000,N,00059.00000,W,1,04,1.80,1.2,m,47.7,M,,*7F?' '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~5110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'Gosub rd_adc0 'Gosub demo_cntr 'examples of messages [Call wr_msg--wr_msg_big---scroll_msg---scroll_big_msg--clr_row] msg1 = "TIME" + msg1 'menu1 assign menu string to msg1 string Call wr_msg(0, 0, msg1) Goto main End 'this subr extrcats 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 Case 1 Hserout "Header=", msg1, CrLf Case 2 Hserout "Location=", msg1, CrLf Case 3 strlat = LeftStr(msg1, 8) sinlat = StrValS(strlat) Hserout "N=", strlat, CrLf 'test only Case 5 strlong = RightStr(msg1, 8) sinlong = StrValS(strlong) Hserout "W=", strlong, CrLf Case 12 stralt = msg1 sinalt = StrValS(stralt) Hserout "Alt", stralt, CrLf Case Else EndSelect msg1 = "" Return 'VVVVVVVVVVVVVVVVVVVVVVVVVV PROC VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ''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 'command 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 font1.bas Next x 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 'WaitMs 5 ''' '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 'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV GOSUBS VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV 'reset the lcd rst_lcd: lcd_reset = 1 WaitMs 10 lcd_reset = 0 WaitMs 10 lcd_reset = 1 Return 'convert any binary value from 0000h To ffffh To 0000 To 65535 decimal 'just name the binary word as b2aval and call this subr and the ASCII 'result will be in ascbfr4,3,2,1,0, ready for your LCD or UART 'just pop the DP in the output to the LCD [as shown above] bin2asc: ascbfr4 = b2aval / 10000 temp3 = b2aval Mod 10000 ascbfr3 = temp3 / 1000 temp3 = b2aval Mod 1000 ascbfr2 = temp3 / 100 temp3 = temp3 Mod 100 ascbfr1 = temp3 / 10 ascbfr0 = temp3 Mod 10 'results are BCD so 'convert To ascii For lcd Or uart ascbfr4 = ascbfr4 Or 0x30 ascbfr3 = ascbfr3 Or 0x30 ascbfr2 = ascbfr2 Or 0x30 ascbfr1 = ascbfr1 Or 0x30 ascbfr0 = ascbfr0 Or 0x30 Return Goto main Return clearscreen: msg1 = clearscn Call wr_msg(0, 0, msg1) Call wr_msg(0, 1, msg1) Call wr_msg(0, 2, msg1) Call wr_msg(0, 3, msg1) Call wr_msg(0, 4, msg1) Call wr_msg(0, 5, msg1) Return 'all four quadrants 'test1 '$GPGGA,Test,5001.00000,N,00059.00000,W,1,04,1.80,1.2,M,47.7,M,,*7F? 'test2 '$GPGGA,Test,4959.00000,N,00059.00000,W,1,04,1.80,250.0,M,47.7,M,,*7F? 'test3 '$GPGGA,Test,4959.00000,N,00101.00000,W,1,04,1.80,500.0,M,47.7,M,,*7F? 'test4 '$GPGGA,Test,5001.00000,N,00101.00000,W,1,04,1.80,1000.0,M,47.7,M,,*7F? 'home '$GPGGA,Home,5051.07400,N,00106.76800,W,1,04,1.80,20.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? 'nonsense tests '$GPGGA,164803?$GPGGA,164803?$GPGGA,164803?$GPGGA,164803?$GPGGA,164803? '$A0123456789?$B0123456789?$C0123456789?$D0123456789?$E0123456789? 'A0123456789?$B0123456789?$C0123456789?$D0123456789?$E0123456789? 'Putty examples '$GPTXT,01,01,02,u-blox ag - www.u-blox.com*? '$GPGGA,164803,,,,,1,04,1.80,,,47.7,M,,*77?