PDA

View Full Version : Serial GPS to 20x4 LCD via PIC16f628-04



Almightyrastus
- 8th May 2006, 17:31
Hi there, I have been lurking around these forums and others for a while trying to find the bits I need and have steadily reached the tearing my hair out point.

I have a Fortuna U2 GPS module that outputs an NMEA string serially, I want to grab this string and parse it into the separate sections then output the data to a Powertip PC2004A screen (in 4 bit mode), possibly on separate pages.

I have been finding various bits and pieces of code here and there for the initialisation of the screen and reading in the data and such but I cannot see how to fit these things together to make a set of code that will work for me and what I need. I have made the required electrical connections to the pic and the screen and now just need to program the code I need.

Does anyone know of either:

A set of code that will do this for me or

Blocks of code that can be fitted together in a logical and simple way to get the code I require?

A lot of the code I have found so far has little to no commenting in so I have been unable to work out what does what and where (hence the tearing hair out bit).

Many thanks in advance for any help anyone can give me.

Travin77
- 8th May 2006, 22:35
First of all, do you need to poll the gps to get the info or does it automatically send the data? If it automatically sends the data, look at the datasheet to determine the format of the string. Then, have your pic wait for the first character of the data string and put the following values into an array. Then just deal with the array. For example: This is using a 16f876a with a 20 mhz osc and the melabs bootloader with microcode studio and PBP, with a 4x20 lcd screen. Also a word of advice, during connection, put a 10uf cap between pins 19 and 20 (or vss and vdd). Now for the code.

@ device pic16F876A, hs_osc, wdt_on, lvp_off, protect_off
include "MODEDEFS.BAS"
define LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 1
DEFINE LCD_lines 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
define OSC 20
adcon1=7
gps_data var byte [12] ' this is the array you are putting the data into I assuming the data will fit in the [12], if not just make it bigger.
'_________________________________________________ ____
Pause 1000
lcdout $fe,1

Start:

serout2,porta.5,84,[poll command] ' use this line if the gps receiver requires a polling command for data.

SERIN2 PORTa.4,84,[WAIT(x),STR gps_data\12] 'x being the first part of the serial string.
lcdout str gps_data\12
pause 1000
goto start

Hopefully this gives you a start. One more thing, the number "84" after the porta.4 and porta.5 is the baud rate number used in serout2 command. It represents 9600 baud, 8 bits, one stop bit, no parity. To change this, look on page 141 of the picbasicpro guide book.

Travin