CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

GPS interface with pic16f microcontroller

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Velraj



Joined: 11 Mar 2014
Posts: 2

View user's profile Send private message

GPS interface with pic16f microcontroller
PostPosted: Tue Mar 11, 2014 4:39 am     Reply with quote

Can anyone know the working ccs code to interface gps with pic16f877a microcontroller ????? Pls do help as it is my amateur project at the earliest .....
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Tue Mar 11, 2014 4:56 am     Reply with quote

Use the forum search.

There is a complete library in the 'code library' section, and several dozen examples in this forum as well.
pathmasugu



Joined: 21 Feb 2014
Posts: 25

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number

PostPosted: Tue Mar 18, 2014 1:46 am     Reply with quote

HI,
you just try this code .............


Code:

#include <18F452.h>
#use delay(clock=20000000)
#Fuses HS
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=GPS,errors)
#byte portb=0xf81
#byte trisb=0xf92

#BYTE TRISC=0XF94
#include "flex_lcd.c"

 
 
   
   int i=0,j=0,flag=0;
   int8 data_gps[77],count=0;
   char data,lati_data[11],longi_data[12];
  // int8 tepmtest[7],test[]="$GPGGA,";
 

#INT_RDA
void rx_data(void)

      data_gps[i++]=getch();  // Store data in Reception regist   
      if(i==77)
      {
      count=i;
      i=0;
      }
}
char bgetch()
{
   char c;
   while(count==0);
   c=data_gps[j];
   if(++j > 77)
   j=0;
   if(count)
   {
      count--;
   }   
   return c;
}


void main()
{
int i;
   trisb=0;
   TRISC=0x80;
   DELAY_MS(100);
   lcd_init();
   lcd_gotoxy(0x0f,1);
   lcd_putc('A');
   lcd_gotoxy(0x0f,2);
   lcd_putc('B');
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);   
   while(true)
      {
         data=bgetch();
         if(data=='$')
            {     
            data=bgetch();
               if(data=='G')
                  {
                  data=bgetch();
                  if(data=='P')
                     {
                     data=bgetch();
                     if(data=='G')
                        {
                        data=bgetch();
                        if(data=='G')
                           {                           
                           data=bgetch();
                           if(data=='A')
                              {
                              data=bgetch();
                              if(data==',')
                                 {
                                 data=bgetch();
                                 while(data!=',')
                                 data=bgetch();
                                 for(i=0;data!='N';i++)
                                 {
                                 data=bgetch();
                                 lati_data[i]=data;  // Store the Latitude data
                                 }
                                 data=bgetch();
                                 if(data==',')
                                 {
                                 for(i=0;data!='E';i++)
                                 {
                                 data=bgetch();
                                 longi_data[i]=data;  // Store the Longitude data
                                 }
                                 }
                                 i=0;
                                 lcd_gotoxy(1,1);
                                 while(i<11)
                                 {
                                 lcd_putc(lati_data[i]);   // Print the Latitude data
                                 i++;
                                 }
                                 i=0;
                                 lcd_gotoxy(1,2);
                                 while(i<12)
                                 {
                                 lcd_putc(longi_data[i]);     // Print the Longitude data
                                 i++;
                                 }   
                                 }     
                                 
                              }
                          }
                     }
                  }
               }
            }
           
            for(i=0;i<12;i++)
            {
               data=0;
               lati_data[i]=0;
               longi_data[i]=0;
            }

        }
}
 

 



_________________
ROCK RAJ
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Tue Mar 18, 2014 6:09 am     Reply with quote

Hello Velraj,

Given that you haven't provided any information as to whether you know electronics and programming, it'll be difficult to help. But here are my thoughts:

First thing, the way to physically interface to the GPS depends on the manufacturer. Some of them might use I2C, others SPI, others a UART. These are all different and you need to understand how they work.

Word of advice: I use a Salea logic analyzer... this is a MUST HAVE tool. The 8 channel version is about 150 dollars (Canadian) and it has saved my butt numerous times, especially with the SPI and I2C ports. A UART is somewhat easy to troubleshoot because it is simple.

The physical interface between the GPS and the PIC also depends on the voltage levels of the signals between the devices; don't connect a 5V PIC to a 3.3V GPS unless the GPS can handle 5V tx/rx.

You also need to make sure that the physical connectivity between your PIC and your GPS is working, so, given that the 877 devices have two serial ports if I remember - one is (I think) C0 and C1, the other is like C6 and C7 - you have to take the time to test both UARTS. Tie one of them to a serial console (e.g. a PC running Hyper Terminal with the proper level converter between the PIC and the PC) and ensure you can display text on your screen and if you type on your keyboard, display something else. This will ensure that bi-directional communications works. Repeat this step for both UARTS.

Once you can display "Hello world" on the PC, _then_ you can start interfacing with the GPS.

Second, there are LOTS of GPS messages and they are all comprised of various message lengths and depending on some units, yours might send you a GPS coordinate every second, or 5 per second or 10 per second. Your PIC needs to be able to handle such message rate, queue the messages and process them further. It also depends if you want to parse NMEA data or other types of messages (UBLOX even has a binary output).

So, all this boils down to... Before you start plugging-away and coding anything, make sure you understand:

1) You need to understand electronics and programming;
2) The basics of the PIC you're using;
3) Make sure it is functional and that you can talk to it;
4) Make sure you understand how the GPS works;

Hope this helps, you didn't provide more details.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group