This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with parsing GPS data through MicroController

GPS Module: Sony GXB5210
uController:: At89c51:
Baud Rate: 9600
Xtal: 11.0592 MHz

IDE: keil uVision

Example Sentence to read and parse: $GPRMC,123519,A,057.0380,N,074.0000,E,022.4,084.4, 230394,003.1,W*6A

Output: latitude and longitude in 3 parts(degrees, minutes, seconds)

Me and four of my friends are working on a GPS-related project. To read and parse the GPS data, we have written a code in C that just extracts values of longitude and latitude from the output of GPS module, and wastes all other data. When we run this code in TURBO-C compiler, with serial port of PC connected to GPS module, the output is exactly how we want it to be, i.e. latitude and longitude in 3 parts(degrees, minutes, seconds). But when we write the code on our micro-controller (At89c51), link the GPS module with it, and take the output on its P1 using LED's on a trainer, most of the times, the value(in binary) of latitude is correctly shown, but the value of longitude shown is wrong. The rest of the times, the LED's just dies off right after turning the trainer On.

So please can anyone explain what might be the problem!

Below is our C-code.

Thanx.

#include <stdio.h>
#include <stdlib.h>
#include <reg51.h>


void delay(int);
char a, array[10];
char temp[5];
unsigned int latd, longd, latm, longm, num_comma, chk, i;
float lats, longs;
char data_type[5];


void main(void)
{

   TMOD = 0x20;       // 8-bit autoreload for timer 1
   TH1 = 0xFD;         // baud rate of 9600
   TR1 = 1;         // start timer 1
   SCON = 0x50;      // 8-bit UART mode and receiver enabled
   IE = 0x90;          // enable to serial port

   data_type[0]='G';
        data_type[1]='P';
        data_type[2]='R';
        data_type[3]='M';
        data_type[4]='C';

   while (1)
   {

      a = _getkey();
      chk = 1;

      if (a == '$')
      {
          i = 0;
            for (i=0;i<=4;i++)
         {
               a = _getkey();
               if (a != data_type[i]){
                 chk = 0;
                  break;
               }
            }

          if (chk==1)
          {

            num_comma=0;
            while (num_comma!=2)
            {
               a = _getkey();
               if (a == 44)
               num_comma++;
            }

            a = _getkey();

            if (a == 86)
            {

               i = 0;
               while (1)
               {
                  a = _getkey();
                  if (a == 44)
                  {
                     array[i]='\0';
                     array[i+1]='\0';

                     temp[0] = array[0];
                     temp[1] = array[1];
                     temp[2] = '\0';

                     latd = atoi(temp);

                     temp[0] = array[2];
                     temp[1] = array[3];
                     temp[2] = '\0';

                     latm = atoi(temp);

                     for (i = 5; i<=8; i++)
                     {
                        temp[i-5]= array[i];
                     }
                     temp[5] = '\0';

                     lats = atoi(temp) / 10000.0;
                     lats = lats * 60;

                     break;
                  }
                  else
                  {
                     array[i] = a;
                     i++;
                  }
                }
               a = _getkey();
               a = _getkey();
               i = 0;
               while (1)
               {
                  a = _getkey();

                  if (a == 44)
                  {
                     array[i]='\0';

                     temp[0] = array[0];
                     temp[1] = array[1];
                     temp[2] = array[2];
                     temp[3] = '\0';

                     longd = atoi(temp);


                     temp[0] = array[3];
                     temp[1] = array[4];
                     temp[2] = '\0';

                     longm = atoi(temp);

                     for (i = 6; i<=9; i++)
                     {
                        temp[i-6]= array[i];
                     }
                     temp[5] = '\0';

                     longs = atoi(temp) / 10000.0;
                     longs = longs * 60;

                     P1 = 0x00;
                     delay(500);
                     P1 = latd;
                     delay(500);
                     P1 = latm;
                     delay(500);
                     P1 = lats;      /* Interested in only the
integer part */

                     delay(500);
                     P1 = longd;
                     delay(500);
                     P1 = longm;
                     delay(500);
                     P1 = longs;      /* Interested in only the integer part */
                     delay(500);

                     break;
                  }
                  else
                  {
                     array[i] = a;
                     i++;
                  }
               }
            }
         }
      }
    }
 }


void delay(int time)
{
unsigned int i,j;
for (i=0;i<time;i++)
for (j=0;j<1275;j++);

}

Parents Reply Children