Need Help on GPS interfacing with PIC18F4550.

Status
Not open for further replies.

zarazagoza

Newbie level 3
Joined
May 9, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,296
I am trying to interface GPS module EM406A with pic18F4550. I want to get longitude and latitude displayed on the lcd. but i seem cannot make it work.
here is my coding.
Code:
#include <p18F4550.h>
#include <delays.h>

/*device configuration*/
#pragma config WDT = OFF, LVP = OFF, FOSC = HS, XINST = OFF
#pragma code isr = 0x08
#pragma	interrupt isr

void SendLCD(unsigned char Byte, char type);
void E_TOG(void);
void SendNyb(unsigned char Byte);
void LCD_Init(void);
void SetLine (char line);
void LCD_String(unsigned rom char *string);
void config (void);
void isr (void);
void tx_data(unsigned char);

#define LCD LATA //LCD Latch PORT
#define LCD_RS LATAbits.LATA4 //Register Select (0: Instruction/ 1: Data)
#define LCD_E LATAbits.LATA5 //Enable (Starts data read/write)
#define LCDT TRISA //LCD Tris port

unsigned char rx_data(void);
unsigned char serial_data;
unsigned char longi_data[12];
unsigned char lati_data[12];
unsigned char data,value=0;
unsigned int i=0,pos;

void main()
{
	char x,tmp; //Some Variables
	//OSCCON = 0x72; //8MHz clock/while(!OSCCONbits.IOFS); //Wait for OSC to become stable
	ADCON1 = 0x0F; //Make all pins digital
	LCD_Init(); //Initialize the LCD
	config();	
	while(1)
	{
		data=rx_data();                     // Check the string '$GPGGA,'
		if(data=='$')
		{
			data=rx_data();
			if(data=='G')
			{
				data=rx_data();
				if(data=='P');
				{
					data=rx_data();
					if(data=='G');
					{
						data=rx_data();
						if(data=='G')
						{
						data=rx_data();
						if(data=='A')
						{
						data=rx_data();
						if(data==',')
						{
						data=rx_data();
						while(data!=',')
						data=rx_data();
						for(i=0;data!='N';i++)
						data=rx_data();
						lati_data[i]=data;  // Store the Latitude data
						}
						data=rx_data();
						if(data==',')
						{
						for(i=0;data!='E';i++)
						{
						data=rx_data();
						longi_data[i]=data;  // Store the Longitude data
						}
						}
						i=0;
						//lcdcmd(0x80);
						while(i<11)
						{
						SetLine(1); //Set Line 1
						LCD_String((unsigned rom char*)lati_data[i]); //Send out string
						//lcddata(lati_data[i]);	// Print the Latitude data
						i++;
						}
						i=0;
						//lcdcmd(0xC0);
						while(i<12)
						{
						SetLine(2); //Set Line 2
						LCD_String((unsigned rom char*)longi_data[i]); //Send out string
						//lcddata(longi_data[i]);	  // Print the Longitude data
						i++;
						}
						}
						}
						}
					}
				}
			}
		}
		Delay1KTCYx(1);
		for(i=0;i<12;i++)
		{
			data=0;
			lati_data[i]=0;
			longi_data[i]=0;
		}
}
void config(void)
{
	TXSTAbits.TX9 = 0;
	TXSTAbits.TXEN = 0;
	TXSTAbits.SYNC = 0;
	TXSTAbits.BRGH = 0;
	RCSTAbits.SPEN = 1;
	RCSTAbits.RX9 = 0;
	RCSTAbits.CREN = 1;
	BAUDCONbits.BRG16 = 0;
	SPBRG = 64;
	
	TRISCbits.RC6 = 1;
	TRISCbits.RC7 = 1;
 	//interrupts 
	RCONbits.IPEN = 0;
	INTCONbits.GIE = 1;
	INTCONbits.PEIE = 1;
	PIE1bits.RCIE = 1;
}

void isr (void)
{
	if(PIR1bits.RCIF == 1)
	{
		if(PIR1bits.TXIF == 1)
		{
			TXREG = RCREG;
		}
	}
}

void tx_data(unsigned char data1)	
{
	TXREG = data1;
	while(PIR1bits.TXIF==0);
}

unsigned char rx_data(void)
{
	while(PIR1bits.RCIF==0);
	return RCREG;
}	
void LCD_String(unsigned rom char *string){
while(*string != 0){ //While the data pointed to isnt a 0x00 do below
SendLCD(*string++,1); //Send out the current byte pointed to
}
}
void LCD_Init(void){
LCDT = 0x00; //Set LCD Pins as output
LCD &= 0xF0; //clear only te db4:db7 pins
Delay10KTCYx(3); //delay 15mS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay10KTCYx(1); //delay 5mS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay100TCYx(3); //delay 150uS
SendNyb(0x03); //Function set (Interface is 8 bits long.)
Delay100TCYx(3); //delay 150uS
SendNyb(0x02); //Function set (Interface is 8 bits long.)
Delay100TCYx(1); //delay 50uS
SendLCD(0x28,0); //Function set (Interface is 4 bits long.) 2-lines, 5x8 dots
Delay100TCYx(1); //delay 50uS
SendLCD(0x10,0); //Cursor move, Shift to the Left
Delay100TCYx(1); //delay 50uS
SendLCD(0x06,0); //Increment
Delay100TCYx(1); //delay 50uS
SendLCD(0x0D,0); //Sets entire display On ,cursor Off, and blinking of cursor position ON
Delay100TCYx(1); //delay 50uS
SendLCD(0x01,0); //Clears entire display and sets DDRAM address 0 in address counter.
Delay10KTCYx(1); //delay 5mS
}
void E_TOG(void){
LCD_E = 1; //Set Enable High
Delay10TCY(); //Delay 5uS
LCD_E = 0; //Set Enable Low
}
void SetLine (char line){
if(line == 1) SendLCD(0x80,0); //Send 0x80 to set line to 1
if(line == 2) SendLCD(0xC0,0); //Send 0xC0 to set line to 2
Delay100TCYx(1); //delay 50uS
}
void SendLCD(unsigned char Byte, char type){
char ByteL;
LCD_RS = type; //Set whether it is a Command (0) or Data/Char (1)
ByteL = Byte & 0x0F; //Place Byte in ByteL and Clear the high part of byte
Byte >>= 4; //Shift over Byte by 4
LCD &= 0xF0; //Clear the LCD portion on the PORTA only
LCD |= Byte; //OR the new data to the LCD portion of PORTA (sending high part of byte)
E_TOG(); //Toggle the E(enable)
Delay10TCY(); //Delay 5uS
LCD &= 0xF0; //Same as above
LCD |= ByteL; //Same as above (sending low part of byte)
E_TOG(); //same as above
}
void SendNyb(unsigned char Byte){
Byte &=0x0F; //Clear the top half of byte
LCD &= 0xF0; //Clear the LCD half of PORTA
LCD |= Byte; //OR the new data into LCD part of PORTA
E_TOG(); //Toggle E(enable)
}

can someone point me where i did it wrong?
 

I wanna try to help
i hope i'm right

why while(data!=',') data=rx_data();
i think that doesn't nesecary. The GPS output is NMEA. And u can use array to get utc, latitude,longitude
$GPGGA,161229.487,3723.2475,N,12158.3416,W,1,07,1.0,9.0,M, , , ,0000*18 i found it from nmea reference manual
$GPGGA,utc[10],latitude[9],N,longitude[10],W,etc

example, if u want get the utc,latitude, and longitude
Code:
unsigned char ch;
          unsigned char utc[10];
          unsigned char lat[9];
          char NS,EW;
          unsigned char longt[10];
          int i,j,k;
                ch= rx_data();
                if (ch=='$')
                {      
                        ch= rx_data();
                        if (ch=='G')
                        {      
                                ch= rx_data();
                                if (ch=='P')
                                {   
                                        ch= rx_data();
                                        if (ch=='G')
                                        {    
                                                ch= rx_data();
                                                if (ch=='G')
                                                {     
                                                        ch= rx_data();
                                                        if (ch=='A')
                                                        { 
                                                                ch=rx_data();
                                                                if (ch==',')
                                                                {
                                                                        for(i=1;i<11;i++)
                                                                        {
                                                                                utc[i]=rx_data();
                                                                        }
                                                                        rx_data();// , get the caracter ',' but it just to get the caracter. Just to separate utc[10] and lat[9] 
                                                                        for(j=1;j<10;j++)
                                                                        {
                                                                                lat[j]=rx_data();
                                                                        }
                                                                        rx_data(); // , get the caracter ',' but it just to get the caracter. Just to separate lat[9] and NS 
                                                                        NS=rx_data(); // is it North or South
                                                                        rx_data(); // , get the caracter ',' but it just to get the caracter. Just to separate NS and longt[10] 
                                                                        for(k=1;k<11;k++)
                                                                        {
                                                                                longt[k]=rx_data();
                                                                        }
                                                                        
                                                                        rx_data(); //  , 
                                                                        EW=rx_data();//is it east or west
i think u don't need waiting for ','. Just take the ',' with rx_data as much as simbol ','
I don't know about PIC18F4550. I've work with GPS on ATMega128A and the compiler is codevision avr. with codevision, if i want screen the utc, latitude, and longitude to lcd 2x16, i wrote like this
Code:
lcd_gotoxy(0,0);lcd_puts[utc];delay_ms(1000);
lcd_puts[lat];delay_ms(1000);
lcd_puts[longt];
I'm using lcd_puts[utc] to screen the array to lcd as caracter.
Because of the limitations of our language(i'm indonesia actualy) it was hard to me to explain what i try to said.
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…