SHIFA
Newbie level 2
Hello!
I am doing a project where...we 've connect a Garmin GPS receiver via MAX 232 to Microcontroller and further microcontroller to PC...I've to write a program to recieve the GPS data..NMEA format i.e GPRMC as UTC time, Latitude, Longitude, speed n serially transmit it out via serial port (not to display it on LCD or LED)........i'm nt that good at microcontroller serial programing in C..! Plzz if anybody could help me...??
below is my half done program...I want to knw if this is the right way of doin it??
#include <stdio.h>
#include <stdlib.h>
#include <reg51.h>
//void delay(int);
unsigned char data_type[5] = "GPRMC", a[6], Longitude[],UTC[],Lattitude[];
unsigned char temp[5];
unsigned int chk, i;
void getchar(void)
{
while(RI==0);
data_req=SBUF;
RI = 0;
}
void main(void)
{
TMOD = 0x20; // 8-bit autoreload for timer 1
TH1 = 0xFD; // baud rate of 9600
SCON = 0x50; // 8-bit UART mode and receiver enabled
TR1 = 1; // start timer 1
//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)
{
while(RI==0);
a[0]=SBUF;
RI = 0;
if (a[0] == '$')
{
int i = 0;
for (i=0;i<=4;i++)
{
while(RI==0);
a=SBUF;
RI = 0;;
if (a != data_type)
{
chk=0;
}
else
{
chk=1; }
}
}
}
if (chk==1)
{
i=0;
for (i=0;i<7;i++)
{
a= _getkey();
UTC=a;
}
a= _getkey();
for(i=0;i<=10;i++)
{
a= _getkey();
Lattitude=a;
}
i=0;
for(i=0;i<=12;i++)
{
a= _getkey();
Longitude=a;
}
}
}
i=0;
for(i=1;i<=2;i++)
{
SBUF= UTC;
while(TI==0);
TI=0;
}
} }
---------- Post added at 00:26 ---------- Previous post was at 00:23 ----------
This is wat i received by directly connecting GPS to PC
$GPRMC,102537,A,1301.5790,N,07733.7577,E,000.0,000.0,190211,001.8,W*6F
$GPGGA,102537,1301.5790,N,07733.7577,E,1,11,0.8,949.2,M,-91.3,M,,*62
$GPGSA,A,3,03,06,11,14,16,18,19,24,30,31,32,,1.1,0.8,0.8*32
$GPGSV,3,1,12,03,12,223,42,06,15,211,40,11,12,309,38,14,32,015,25*7C
$GPGSV,3,2,12,16,09,189,26,18,27,099,25,19,14,254,38,24,12,320,42*7D
$GPGSV,3,3,12,30,20,175,21,31,84,218,39,32,06,316,36,21,04,149,00*79
$PGRME,11.0,M,53.0,M,54.1,M*18
$PGRMB,,,,,K,,N,N*01
$PGRMM,WGS 84*06
A C program should parse this data into its constituents....Plzzz Help...!!
I am doing a project where...we 've connect a Garmin GPS receiver via MAX 232 to Microcontroller and further microcontroller to PC...I've to write a program to recieve the GPS data..NMEA format i.e GPRMC as UTC time, Latitude, Longitude, speed n serially transmit it out via serial port (not to display it on LCD or LED)........i'm nt that good at microcontroller serial programing in C..! Plzz if anybody could help me...??
below is my half done program...I want to knw if this is the right way of doin it??
#include <stdio.h>
#include <stdlib.h>
#include <reg51.h>
//void delay(int);
unsigned char data_type[5] = "GPRMC", a[6], Longitude[],UTC[],Lattitude[];
unsigned char temp[5];
unsigned int chk, i;
void getchar(void)
{
while(RI==0);
data_req=SBUF;
RI = 0;
}
void main(void)
{
TMOD = 0x20; // 8-bit autoreload for timer 1
TH1 = 0xFD; // baud rate of 9600
SCON = 0x50; // 8-bit UART mode and receiver enabled
TR1 = 1; // start timer 1
//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)
{
while(RI==0);
a[0]=SBUF;
RI = 0;
if (a[0] == '$')
{
int i = 0;
for (i=0;i<=4;i++)
{
while(RI==0);
a=SBUF;
RI = 0;;
if (a != data_type)
{
chk=0;
}
else
{
chk=1; }
}
}
}
if (chk==1)
{
i=0;
for (i=0;i<7;i++)
{
a= _getkey();
UTC=a;
}
a= _getkey();
for(i=0;i<=10;i++)
{
a= _getkey();
Lattitude=a;
}
i=0;
for(i=0;i<=12;i++)
{
a= _getkey();
Longitude=a;
}
}
}
i=0;
for(i=1;i<=2;i++)
{
SBUF= UTC;
while(TI==0);
TI=0;
}
} }
---------- Post added at 00:26 ---------- Previous post was at 00:23 ----------
This is wat i received by directly connecting GPS to PC
$GPRMC,102537,A,1301.5790,N,07733.7577,E,000.0,000.0,190211,001.8,W*6F
$GPGGA,102537,1301.5790,N,07733.7577,E,1,11,0.8,949.2,M,-91.3,M,,*62
$GPGSA,A,3,03,06,11,14,16,18,19,24,30,31,32,,1.1,0.8,0.8*32
$GPGSV,3,1,12,03,12,223,42,06,15,211,40,11,12,309,38,14,32,015,25*7C
$GPGSV,3,2,12,16,09,189,26,18,27,099,25,19,14,254,38,24,12,320,42*7D
$GPGSV,3,3,12,30,20,175,21,31,84,218,39,32,06,316,36,21,04,149,00*79
$PGRME,11.0,M,53.0,M,54.1,M*18
$PGRMB,,,,,K,,N,N*01
$PGRMM,WGS 84*06
A C program should parse this data into its constituents....Plzzz Help...!!