The Global Positioning System (GPS) is a space-based satellite navigation system that provides location and time information.The GPS module continuously transmits serial data (RS232 protocol) in the form of sentences according to NMEA standards. The latitude and longitude values of the location are contained in the GPGGA sentence .The serial data from the GPS receiver is taken by using the receiver pin of the controller. This data consists of a sequence of NMEA from which GPGGA sentence is identified and processed.
Example : $GPGGA - Global Positioning System Fix Data
:$GPGGA,132455.970,2651.0145,N,07547.7051,E,0.50,342.76,301010,,,,,,,,,,,
GGA 132453.970 2651.0138, N 07547.7054, E 1
03 7.1 42.5, M 46.9, M |
Global Positioning System Fix Data Fix taken at 13:24:53970 UTC Latitude 26 deg 51.0138' N Longitude 07 deg 54.7054' E Fix quality: 0 = invalid 1 = GPS fix (SPS) 2 = DGPS fix 3 = PPS fix 4 = Real Time Kinematic 5 = Float RTK 6 = Estimated (dead reckoning) 7 = Manual input mode 8 = Simulation mode
Number of satellites being tracked Horizontal dilution of position Altitude, Meters, above mean sea level Height of mean sea level above WGS84 Ellipsoid |
To communicate over UART, we just need three basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground). So to interface UART with 8051, we just need the basic signals. these values are extracted from the GPGGA sentence and are displayed on LCD.
CODE:
#include<reg51.h>
#define lcdport P2
sbit rs=P3^4;
sbit rw=P3^5;
sbit en=P3^6;
char lati[50];
char longi[50];
void clear_variable();
void lcdcmd(char);
void lcdint();
void lcddata(char);
void lcdstring(char *);
void delay(unsigned int);
void uart_int();
unsigned char receive_value();
void transmit(unsigned char);
void latitude();
void longitude();
unsigned char buff;
unsigned char character;
unsigned int i;
void uart_int()
{
TMOD=0x20;
TH1=0xfd;
SCON=0x50;
TR1=1;
}
void clear_variable()
{
unsigned char l;
for(l=0;l<50;l++)
lati[l]=0x00;
}
void main()
{
lcdint();
uart_int();
clear_variable();
delay(500);
lcdstring("WELCOME");
lcdcmd(0xc0);
delay(500);
lcdcmd(0x01);
lcdcmd(0x80);
while(1)
{
character=receive_value();
if(character=='$')
{
character=receive_value();
if(character=='G')
{
character=receive_value();
if(character=='P')
{
character=receive_value();
if(character=='G')
{
character=receive_value();
if(character=='A')
{
character=receive_value();
if(character==',')
{
character=receive_value();
latitude();
while(character!=',')
{
character=receive_value();
}
longitude();
}}}}}}
}
}
void longitude()
{
unsigned char k;
for(k=0;character!=',';k++)
{
lati[k]=receive_value();
}
lcdcmd(0xc0);
lcdstring("Ln:");
lcdcmd(0xc5);
lcddata(longi[0]);
lcddata(longi[1]);
lcdcmd(64); //degree symbol
lcddata(10);
lcddata(17);
lcddata(17);
lcddata(10);
lcddata(0);
lcddata(0);
lcddata(0);
lcddata(0);
lcddata(longi[2]);
lcddata(longi[3]);
lcddata('.');
lcddata(longi[4]);
lcddata(longi[5]);
lcddata(longi[6]);
lcddata(longi[7]);
lcddata(0x27); //minute sign
}
unsigned char receive_value()
{
while(RI==0);
buff=SBUF;
RI=0;
return(buff);
}
void latitude()
{
while(character!=',')
{
character=receive_value();
}
for(i=0;character!=',';i++)
{
lati[i]=receive_value();
}
lcdstring("Lt:");
lcdcmd(0x85);
lcddata(lati[0]);
lcddata(lati[1]);
lcdcmd(64); //degree symbol
lcddata(10);
lcddata(17);
lcddata(17);
lcddata(10);
lcddata(0);
lcddata(0);
lcddata(0);
lcddata(0);
lcddata(lati[2]);
lcddata(lati[3]);
lcddata('.');
lcddata(lati[4]);
lcddata(lati[5]);
lcddata(lati[6]);
lcddata(lati[7]);
lcddata(0x27); //minute sign
}
void delay(unsigned int x)
{
unsigned int i;
for(i=0;i<x;i++);
}
void lcdint()
{
lcdcmd(0x38);
delay(500);
lcdcmd(0x01);
delay(500);
lcdcmd(0x0c);
delay(500);
lcdcmd(0x80);
delay(500);
lcdcmd(0x0e);
delay(500);
}
void lcdcmd(char value)
{
lcdport = value;
rw=0;
rs=0;
en=1;
delay(500);
en=0;
}
void lcdstring(char *p)
{
while(*p!='\0')
{
lcddata(*p);
delay(2000);
p++;
}
}
void lcddata(char value)
{
lcdport = value;
rs=1;
rw=0;
en=1;
delay(500);
en=0;
}
VIDEO
Category: