Hi E,hi C,
Is the top line the GPS Time .?
If Yes, How should it appear.?
E
Hi E,hi C,
I solved a similar problem on our common 5110 project set up by making this change.
Try it.
E
msg_end:
If str1(5) = 0x47 Then 'G'
csv = 0
For txi = 1 To 73 '80 ' actual valid message length =71 + Cr Lf
char = str1(txi)
strchr = Chr(char)
EDIT:hi C,
Post your latest Basic program.
E
Hi E,hi,
It just means changing the .bas to .txt, to post here
'18LF4520 5110 GPS BMP280 COMBINED 110218 0900
'18LF4520 8MHz x4 5110 NEO8 SML 050118 1400
'18lf4520 pcb bmp280 press-temp 080218 0900
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
Symbol yled = PORTA.4 'yled
Symbol rled = PORTA.5 'rled
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 sinlat As Single
Dim sinlong As Single
Dim strtim As String
Dim strlat As String
Dim strlong As String
Dim char As Byte
Dim rxi As Byte
Dim txi As Byte
'BMP280 CALC
Dim var1 As Single
Dim var2 As Single
Dim b(24) As Byte
Dim data As Byte
Dim adc_t As Single
Dim strtp As String
Dim strpr As String
Dim adc_p As Single
Dim t_fine As Single
Dim tp As Single 'TEMP result in CALC
Dim pr As Single 'PRESS result in CALC
Dim t_raw As Long
Dim p_raw As Long
Dim i As Byte
Dim adr As Byte
Dim t1 As Word 'Compensation parameters
Dim t2 As Word
Dim t3 As Word
Dim p1 As Word
Dim p2 As Word
Dim p3 As Word
Dim p4 As Word
Dim p5 As Word
Dim p6 As Word
Dim p7 As Word
Dim p8 As Word
Dim p9 As Word
Dim dig_t1 As Single 'Compensation parameters
Dim dig_t2 As Single
Dim dig_t3 As Single
Dim dig_p1 As Single
Dim dig_p2 As Single
Dim dig_p3 As Single
Dim dig_p4 As Single
Dim dig_p5 As Single
Dim dig_p6 As Single
Dim dig_p7 As Single
Dim dig_p8 As Single
Dim dig_p9 As Single
Disable High
Disable Low
Include "fontsml.bas" 'This 'FONT' 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()
'BMP280
'Compensation parameters
SPICSOn
For i = 0 To 23
PORTD.5 = 0 'CHIP SELECT BMP280 ON
adr = 0x88 + i
SPISend adr
SPIReceive data
b(i) = data
PORTD.5 = 1 'CHIP SELECT BMP280 OFF
Next i
SPICSOff
'Temp coefficents
t1.LB = b(0)
t1.HB = b(1)
t2.LB = b(2)
t2.HB = b(3)
t3.LB = b(4)
t3.HB = b(5)
'pressure coefficients
p1.LB = b(6)
p1.HB = b(7)
p2.LB = b(8)
p2.HB = b(9)
p3.LB = b(10)
p3.HB = b(11)
p4.LB = b(12)
p4.HB = b(13)
p5.LB = b(14)
p5.HB = b(15)
p6.LB = b(16)
p6.HB = b(17)
p7.LB = b(18)
p7.HB = b(19)
p8.LB = b(20)
p8.HB = b(21)
p9.LB = b(22)
p9.HB = b(23)
'convert to singles with sign
dig_t1 = t1
dig_t2 = t2
If dig_t2 > 32767 Then
dig_t2 = dig_t2 - 65536
Endif
dig_t3 = t3
If dig_t3 > 32767 Then
dig_t3 = dig_t3 - 65536
Endif
dig_p1 = p1
dig_p2 = p2
If dig_p2 > 32767 Then
dig_p2 = dig_p2 - 65536
Endif
dig_p3 = p3
If dig_p3 > 32767 Then
dig_p3 = dig_p3 - 65536
Endif
dig_p4 = p4
If dig_p4 > 32767 Then
dig_p4 = dig_p4 - 65536
Endif
dig_p5 = p5
If dig_p5 > 32767 Then
dig_p5 = dig_p5 - 65536
Endif
dig_p6 = p6
If dig_p6 > 32767 Then
dig_p6 = dig_p6 - 65536
Endif
dig_p7 = p7
If dig_p7 > 32767 Then
dig_p7 = dig_p7 - 65536
Endif
dig_p8 = p8
If dig_p8 > 32767 Then
dig_p8 = dig_p8 - 65536
Endif
dig_p9 = p9
If dig_p9 > 32767 Then
dig_p9 = dig_p9 - 65536
Endif
SPICSOn
PORTD.5 = 0 'CHIP SELECT BMP280 ON
SPISend 0x60 'WRITE 0xe0 RESET ADDR [Is this needed?]
SPISend 0xb6 '%10110110 RESET TO 0x00
PORTD.5 = 1 'CHIP SELECT BMP280 OFF
PORTD.5 = 0 'CHIP SELECT BMP280 ON
SPISend 0x74 'WRITE 0xF4 Control CTRL_MEAS reg addr
SPISend 0x5f '%01011111 T/ON P/ON 't_x2 px16 Normal Mode
PORTD.5 = 1 'CHIP SELECT BMP280 OFF
PORTD.5 = 0 'CHIP SELECT BMP280 ON
SPISend 0x75 'WRITE 0xF5 Control CONFIG reg addr
SPISend 0x1c '%00011100 osrs_t 0.5ms Table 11-11R filter x16 table 6
PORTD.5 = 1 'CHIP SELECT BMP280 OFF
SPICSOff
main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
yled = 1
'WaitMs 1
yled = 0
'READ TEMP and PRESS values ADC 20 bit
SPICSOn
For i = 0 To 2
PORTD.5 = 0 'CHIP SELECT BMP280 ON
adr = 0xfa + i
SPISend adr
SPIReceive data
b(i) = data
PORTD.5 = 1 'CHIP SELECT BMP280 OFF
Next i
t_raw.LB = b(2)
t_raw.HB = b(1)
t_raw.3B = b(0)
t_raw = ShiftRight(t_raw, 4)
For i = 0 To 2
PORTD.5 = 0 'CHIP SELECT BMP280 ON
adr = 0xf7 + i
SPISend adr
SPIReceive data
b(i) = data
PORTD.5 = 1 'CHIP SELECT BMP280 OFF
Next i
SPICSOff
p_raw.LB = b(2)
p_raw.HB = b(1)
p_raw.3B = b(0)
p_raw = ShiftRight(p_raw, 4)
adc_t = t_raw
adc_p = p_raw
Gosub calc
strtp = #tp 'From CALC
strpr = #pr 'From CALC
'GPS
Gosub get_neo 'Reads NMEA DATA
Goto main
End
'Await NEO GPS RXD
get_neo: ''$GPGGA,123459.00,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
char = RCREG
If char <> 0x24 Then Goto sync1 '$'
str1(1) = char 'STR1 ARRAY
rxi = 2
get_msg: 'read and save GPGGA msg
If PIR1.RCIF = 0 Then Goto get_msg
char = RCREG
str1(rxi) = char 'STR1 ARRAY
rxi = rxi + 1
If rxi > 79 Then Goto get_neo 'msg bfr over run
If char = 0x0a Or char = 0x3f Then Goto msg_end 'tests for either LF or ?
Goto get_msg
If rxi < 60 Then 'invalid msg
msg1 = ""
Goto get_neo
Endif
msg_end:
If str1(5) = 0x47 Then 'G'
csv = 0
For txi = 1 To 73
char = str1(txi)
strchr = Chr(char)
If strchr <> "," Then
msg1 = msg1 + strchr
Else
csv = csv + 1
Gosub get_val
Endif
Next txi
Else
msg1 = ""
Goto get_neo
Endif
msg1 = "LAT=" + strlat
Call wr_msg(0, 1, msg1)
msg1 = "LON=" + strlong
Call wr_msg(0, 2, msg1)
msg1 = "TMP= " + strtp
Call wr_msg(0, 4, msg1)
msg1 = "PRS= " + strpr
Call wr_msg(0, 5, msg1)
msg1 = "TIM= " + strtim
Call wr_msg(0, 0, msg1)
''Hserout " T=", strtim, " N=", strlat, " W=", strlong, " A=", stralt, CrLf
strtim = ""
strlat = ""
strlat = ""
strlong = ""
strtp = ""
strpr = ""
msg1 = ""
Return
'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 POSITION 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
Case Else
EndSelect
msg1 = ""
Return
calc: 'BMP280
'Calculate temperature
var1 = ((adc_t / 16384 - (dig_t1 / 1024))) * dig_t2
var2 = (((adc_t) / 131072 - (dig_t1) / 8192) * (adc_t / 131072 - dig_t1 / 8192) * dig_t3)
t_fine = var1 + var2
tp = (var1 + var2) / 5120
'Calculate pressure
var1 = t_fine / 2 - 64000
var2 = var1 * var1 * dig_p6 / 32768
var2 = var2 + var1 * dig_p5 * 2
var2 = var2 / 4 + dig_p4 * 65536
var1 = ((dig_p3) * var1 * var1 / 524288 + dig_p2 * var1) / 524288
var1 = (1 + var1 / 32768) * dig_p1
pr = 1048576 - adc_p
pr = (pr - (var2 / 4096)) * 6250 / var1
var1 = dig_p9 * pr * pr / 2147483648
var2 = pr * dig_p8 / 32768
pr = pr + (var1 + var2 + dig_p7) / 16
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
'Reset the lcd
rst_lcd:
lcd_reset = 1
WaitMs 10
lcd_reset = 0
WaitMs 10
lcd_reset = 1
Return
Morning E,@camerart
hi C,
Cut and paste these routines over the existing named routines in your posted program.
Note:
I have marked the lines with comments and ''''
E
Hi E,hi,
Check this marked up version.
E
Hi E,hi,
I was not using a sim.
Its running in a18F4520 alongside me now at this moment, has been OK for 2 days.
The PIC is getting data from the GPS NEO and displaying the T,N,W data on a 5110 in real time.
It is running the same program as I have posted.
No artefacts on the LCD, even when using your posted program.
You must have a problem elsewhere in your set up.
E
Hi E,hi C,
What I did I extracted the 'bits' of your program that drives the 5110 with data from the GPS, it worked OK in a PIC.
I modified the length of the Lat Long values, because they were being truncated and not showing the correct data.
If you use long name labels it does not leave enough room on the 5110 line to show the full data value.
I was going to take a pic of the 5110 to post, but as you know it will show my precise location to the rest of the planet.!!
I know I could edit it out, but it may appear I am trying to fudge the display.
E
by Jake Hertz
by Aaron Carman
by Duane Benson
by Aaron Carman