reading data from (adafruit ultimate GPS v3) using PIC18f455

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
dreemoo
 
Posts: 2
Joined: Thu May 01, 2014 4:12 am

reading data from (adafruit ultimate GPS v3) using PIC18f455

Post by dreemoo »

hi

recently I've purchased this (adafruit ultimate GPS v3), and I've tried to interface it with PIC18f4550 to display longitude & latitude on an LCD.
the problem is that I only get the information clearly once, then when the code is repeating itself I got some undefined data and then It stop showing anything until I push the PIC18 reset button.

this is the code that I'm using

Code: Select all

 
//  Last Modified: 27/04/2014

#include<p18f4550.h>
#include<delays.h>
#define FREQ 12000000  // this is crystal value 
#define baud 9600 // baud rate that supported by GPS
#define spbrg_value (((FREQ/64)/baud)-1)

#pragma config PLLDIV = 3
#pragma config CPUDIV = OSC1_PLL2
#pragma config FOSC = HS
#pragma config MCLRE = ON
#pragma config WDT = OFF, DEBUG = OFF
#pragma config LVP = OFF
#pragma config PWRT = OFF 
#pragma config PBADEN = OFF
#pragma config ICPRT = OFF
 

 //    defining LCD PORT   
 //---------------------------------
#define ldata PORTD    
#define rs PORTCbits.RC0
#define rw PORTCbits.RC1
#define en PORTCbits.RC2
 


 //Defining the LCD commands
//------------------------------------------
void lcdcmd(unsigned char value)
{
ldata = value;
rs = 0;
rw = 0;
en = 1;
Delay100TCYx( 30 );
en = 0;
}

 
//Defining the LCD display
//------------------------------------------
void lcddata(unsigned char value)
{
ldata = value;
rs = 1;
rw = 0;
en = 1;
Delay100TCYx( 30 );
en = 0;
}


// LCD initialization 
// ------------------------------


void lcd_ini()
{
lcdcmd(0x38);	//LCD matrix
Delay10KTCYx( 75 );
lcdcmd(0x0E);	//Blink curser
Delay10KTCYx( 4 );
lcdcmd(0x01);	//Clear LCD
Delay10KTCYx( 4 );
lcdcmd(0x06);	  //increment curser
Delay10KTCYx( 4 );
lcdcmd(0x80); //start at firs line, first position
Delay10KTCYx( 4 );
}



  receiving data from GPS
//---------------------------------------
unsigned char rx_data(void)
{
while(PIR1bits.RCIF==0); // Wait until RCIF gets low
return RCREG; // Store data in Reception register
}

 
 
 //  ** THE MAIN FUNCTION **

void main()
{


TRISD = 0;  //Set it output for the LCD
TRISCbits.RC0 = 0; //Set it output for RS
TRISCbits.RC1 = 0; //Set it output for RW
TRISCbits.RC2 = 0; //Set it output for en
TRISCbits.RC7 = 1; //RX pin set as input
 

SPBRG=spbrg_value; //Fill SPBRG register to set the baud rate
RCSTAbits.SPEN=1; // To activate serial port (Tx and Rx pins)
RCSTAbits.CREN=1; // To enable continuous reception
 


while(1)
{



unsigned char ch;
unsigned char utc[10]= {0};
unsigned char lat[9]= {0};
char NS,EW;
unsigned char longt[10]= {0};
  int i,j,k;

again: 
lcd_ini(); //initialize the LCD


   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
                                                                }
                                                        } else goto again;
                                                } else goto again;
                                        } else goto again;
                                }
                        }
   }  

//display Latitude & Longitude
    lcdcmd(0x80);
   for(j=1;j<10;j++)
     {
       lcddata(lat[j]);
     }
   lcddata(',');
   lcddata(NS);

   lcdcmd(0xC0);
    for(k=1;k<11;k++)
     {
      lcddata(longt[k]);
     }
   
     lcddata(',');
     lcddata(EW);
                                  
 
Delay10KTCYx( 250);  // some delay (1000ms)
Delay10KTCYx( 250);
 
 

lcdcmd(0x01);	 //CLEAR DISPLAY AND DDRAM CONTENT
Delay10KTCYx( 250);

   

  

 
}



}
this is when the code start running
this is when the code start running
DSC_0415 (640x360).jpg (183.97 KiB) Viewed 427 times
this is when the code is repeating
this is when the code is repeating
DSC_0416 (640x360).jpg (184.43 KiB) Viewed 427 times

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: reading data from (adafruit ultimate GPS v3) using PIC18

Post by Franklin97355 »

That looks like you are sending garbage to the LCD. Can you set up a program that just prints the strings the GPS outputs?

dreemoo
 
Posts: 2
Joined: Thu May 01, 2014 4:12 am

Re: reading data from (adafruit ultimate GPS v3) using PIC18

Post by dreemoo »

franklin97355 wrote:That looks like you are sending garbage to the LCD. Can you set up a program that just prints the strings the GPS outputs?
how can I do that ?
do u mean like I make a condition at each line ?

and thanks for replying

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: reading data from (adafruit ultimate GPS v3) using PIC18

Post by Franklin97355 »

Not sure how you would do that with a pic but the GPS outputs serial data so you can display that in a terminal window.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”