Localizador de cidades baseado em microcontrolador usando GPS e LCD

Microcontroller based city finder using GPS and LCD

GPS receiver is used to obtain precise geographic locations by receiving information from satellites. It receives information from satellites and provides location information in terms of latitude and longitude. Provides latitude and longitude with degree-minute-second accuracy. Using these latitude and longitude coordinates one can easily track location across the globe.

The GPS receiver provides serial output in the form of strings with NMEA ( National Marine Electronics Association ) Protocol 0183. These strings are received serially by a host computer or host processor/controller for display or to take any decision or action. The following figure shows the output of the GPS receiver on the desktop computer's hyperterminal.

Captura de tela do aplicativo HyperTerminal mostrando cadeias de protocolo NMEA 0183 recebidas do receptor GPS NEO-6M

Figure 1: HyperTerminal application screenshot showing NMEA 0183 protocol strings received from the NEO-6M GPS receiver

NMEA Protocol:

The NEMA protocol provides standard and GPS receiver-supplied messages. Some of the standard messages issued by NMEA are GGA, ZDA, VTC, RMC, GSA, GSV, etc. There are 50 NMEA messages, but only a few are applied to the GPS receiver. The maximum length of each message is limited to 79 characters. The NMEA format is provided and explained as

$IDMSG,D1,D2……Dn*CS,(CR)(LF)

  1. $ – indicates the beginning of each message
  2. ID – indicates the source of navigation information. In this case it will be GP because of the GPS
  3. MSG – describes the message content as GGA, GSV, GSA etc.
  4. , – is a separation between data
  5. D1 – Dn – are data fields separated by commas
  6. * – is used to separate checksum
  7. CS – your checksum value in HEX
  8. (CR)(LF) – Your carriage returns + line feed that indicates the end of the message

From the initial tag notation it is possible to identify what type of information will be available in the following string. As

· The string starts with the $GPGGA tag and provides time, latitude, longitude, altitude, GPS quality and some other information

· The string starts with the $GPZDA tag and provides date and time information

The project in question demonstrates how to obtain location information (latitude and longitude) from the GPS receiver and if the received coordinates match any Indian city, it will also display the name of the city. It uses AT89C51 8-bit microcontroller to get data from GPS receiver and display it on LCD. Latitude and longitude coordinates are provided in two different strings that start with the $GPRMC tag or the $GPGGA tag. These strings are highlighted in the figure above and also in the string where the latitude-longitude coordinates are also highlighted. You can extract these coordinates from any string. I extracted it from the GPRMC string. RMC stands for Recommended Minimum GNSS Data . The GPRMC string is explained in more detail below.

GPRMC string format:

Imagem mostrando o formato de string GPRMC contendo informações de hora, latitude e longitude do módulo GPS

Fig. 2: Image showing GPRMC string format containing time, latitude and longitude information from the GPS module

The complete string is 65 to 70 characters long, including the start tag. The string starts with $ and starts with the GPRMC tag. After the start label, the next time is GMT. Then there is location information which includes latitude with direction and longitude with direction. There are 9 characters in latitude. The first two represent the degree (33 in this case), the second represents the minute (54' here) and after the decimal point the last 4 represent the seconds (1133” here). Latitude direction follows latitude and can be 'N' or 'S'. Longitude is represented by the next 10 characters. It is similar to latitude, but there are three digits (characters) in degree (151 in this case). The microcontroller extracts this string from the GPS output, extracts details of the location information and displays it on the LCD in the proper format. It then matches the coordinates with the coordinates of different Indian cities. If a match is found, the city name will be displayed as “is Ahmedabad” or “is Delhi”.

System block diagram:

There are only four main building blocks of the system.

GPS Receiver – It collects information from the satellite and generates results in the form of different strings. It provides these strings as output to the microcontroller

MAX232 – is a level converter chip. It converts RS232 level signals provided by the GPS receiver into TTL level signals that can be provided to the microcontroller.

AT89C51 Microcontroller – it receives all the strings from the GPS receiver, but extracts only one string. It extracts location information from the string and displays it on the LCD in the proper format

LCD panel – is used to display location information and city name

Diagrama de blocos do localizador GPS baseado em microcontrolador 8051

Fig. 3: Block diagram of 8051 microcontroller based GPS tracker

Circuit description and programming

System circuit diagram:

( See Circuit Diagram Guide for Microcontroller Based City Finder Using GPS and LCD )

Circuit Description

As shown in the figure, the circuit is built using only three main components, RS232 MAX232 level converter chip, 89C51 microcontroller and 16×2 LCD panel.

· The GPS module has three interface terminals called Tx, Rx and Gnd. It provides series of strings as serial output through its Tx pin. Therefore, the Tx pin is connected to the RS232 level side input pin R2IN (pin 8)

· The output is taken from the TTL level side output pin R2OUT (pin no. 9) and is supplied to the serial receive pin Rx (pin 10) of the AT89C51

· Capacitors C1 – C4 are connected to the MAX232 chip according to the circuit suggested in its technical sheet

· PORT2 pins P2.0 – P2.7 drive LCD data pins D0 – D7. LCD control pins Rs, RW and En are connected to pins P3.7, P3.6 and P3.5 of PORT3 respectively

· A 1 KΩ potentiometer is connected to pin 3 of the LCD as shown to vary its brightness

· A 12 MHz crystal along with two 22 pF capacitors are connected to crystal input pins 18 and 19 of AT89C51 as shown

· The complete circuit works with 5 V power supply

Circuit Operation:

The complete operation of the circuit depends on the GPS receiver module. The GPS receiver module provides 10 different strings as output which contains various information like longitude, latitude, altitude, date, time, speed, number of satellites in visibility, validity of received signal, signal strength, etc. character by character to the microcontroller.

The AT89C51 microcontroller is the heart of the complete circuit. It performs the following tasks

· Receives series of strings from the GPS module

· Extracts the required string from a bunch of strings received in real time

· From the extracted string, it also extracts location information

· Finally displays this information on the LCD panel

· Continuously receives data from the GPS module in real time and updates the LCD every 4 seconds

AT89C51 will receive all strings character by character. From these 10 strings, it extracts the string starting with $GPRMC. All other strings are simply discarded. From the string after the $GPRMC tag, the microcontroller will extract only latitude and longitude along with its direction.

After extracting the information, it displays it on the LCD panel as

  1. Latitude – latitude direction and degrees-minutes-seconds
  2. Longitude – direction of longitude and degrees-minute-second

These latitudes and longitudes are compared with the latitude-longitude of major cities in INDIA like Mumbai, Delhi, Ahmedabad, Channai, Kolkata, Bangluru, Bhopal, Pune, Jaipur etc. and city coordinates) the message is displayed on the LCD as “It's a Ahmedabad”. The city name is displayed for about 5 seconds and again the latitude and longitude are displayed. Therefore, if the GPS receiver is stable at a city location, it will display the city name repeatedly.

Note: In this project, for demonstration, I have used long coordinates of most of the metropolitan cities in INDIA like Mumbai, Delhi, Bangaluru, Ahmedabad, Jaipur, etc. The city name will only be displayed when the received coordinates exactly match the specified coordinates in degrees and minutes. You can change the coordinates in the program for the same city or enter completely new coordinates for any other city. It may be better to enter city coordinates for any state only. For just a slight modification, if one enters coordinates of different city landmarks with place names instead of city names, then this project can be used to locate different city landmarks.

Software program:

The microcontroller's functionalities are due to the program embedded in its internal FLASH. The software program is written in C language using KEIL software (IDE). The program is compiled using the Keil cross-compiler. When the program compiles successfully, it generates a HEX file. This HEX file is loaded into the AT89C51 using a suitable EEPROM programmer.

The C program is made up of 9 different functions described below

LCD handling functions

  1. LCD_cmd – this function sends an 8-bit (character) command to the LCD to initialize or configure it
  2. LCD_data – this function sends 8-bit (character) data to the LCD that will be displayed on the screen
  3. LCD_write_string – this function displays the complete string (message) on the LCD screen
  4. Init_LCD – this function initializes the LCD in 8-bit mode, 8×5 dots/character, etc.

USART manipulation function

  1. Init_usart – initializes the built-in USART and sets the baud rate to 4800 bps
  2. usat_getch – returns a character (8-bit data) received from the serial port

Display functions

  1. display_latitude – displays the latitude received on the LCD in degree-minute-second format
  2. display_longitude – displays the longitude received on the LCD in degree-minute-second format
  3. get_city_name – calculates the coordinate value, matches it with the city coordinates and when the match is found displays the city name

Along with these 9 user-defined functions, there is one main function. Initializes ports as input or output. It then initializes the LCD and USART and goes into a continuous loop. In this continuous loop, first wait until you get the first 5 characters like $, G, P, R, M and C. When you get all these 5 characters in sequence, that means it is the required string with $GPRMC tag. From this string, one by one, extract latitude and longitude. In the standard GPS string format, the required values ​​are given between two commas. So the program will start collecting characters (data) from one coma and continue until the next coma. Here is the complete software with the necessary comments

Project source code

#include

//#define LCD_DATA_PORT P2 //LCD data port

sbit rs = P3^7; //enable signal

sbit rw = P3^6; //read/write signal

sbit en = P3^5 ; //resister select signal

unsigned char value,lati_value(10),lati_dir, longi_value(11), longi_dir;

unsigned int t;

void lcd_busy

{

int p;

for(p=0;p<2000;p++);

}

void LCD_cmd(unsigned char cmd)

{

lcd_busy;

rw=0;

rs=0;

P2 = cmd;

en=1;

en=0;

}

void LCD_data(unsigned char dat)

{

lcd_busy;

rw=0;

rs=1;

P2 = date;

en=1;

en=0;

}

void init_LCD

{

LCD_cmd(0x38); //initialization of 16X2 LCD in 8bit mode

LCD_cmd(0x0E); //cursor ON

LCD_cmd(0x01);

LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position

}

void init_USART

{

TMOD=0x20;

SCON=0x40;

TH1=0xFD;

TL1=0xFD;

TR1=1;

REN=1;

}

unsigned char user_getch

{

while(RI==0);

RI=0;

return(SBUF);

}

void LCD_write_string(char *str) //take address value of the string in pioneer *str

{

int i=0;

while(str(i)!='�') // loop will go on till the NULL characters

{

LCD_data(str(i)); // sending data on CD byte by byte

i++;

}

return;

}

void display_lat

{

LCD_cmd(0x80);

LCD_write_string("lt:");

LCD_data(lati_dir);

LCD_data(0x20);

LCD_data(lati_value(0));

LCD_data(lati_value(1));

LCD_data(0xDF);

LCD_data(lati_value(2));

LCD_data(lati_value(3));

LCD_data(0x27);

LCD_data(lati_value(5));

LCD_data(lati_value(6));

LCD_data(lati_value(7));

LCD_data(lati_value(8));

LCD_data(0x22);

}

void display_logn

{

LCD_cmd(0xC0);

LCD_write_string("lg:");

LCD_data(longi_dir);

LCD_data(longi_value(0));

LCD_data(longi_value(1));

LCD_data(longi_value(2));

LCD_data(0xDF);

LCD_data(longi_value(3));

LCD_data(longi_value(4));

LCD_data(0x27);

LCD_data(longi_value(6));

LCD_data(longi_value(7));

LCD_data(longi_value(8));

LCD_data(longi_value(9));

LCD_data(0x22);

}

void delay_5sec

{

int i,j;

for(i=0;i<100;i++)

for(j=0;j<10000;j++);

}

void get_city_name

{

unsigned int value1,value2,value3;

unsigned int lati_degree,lati_minute,longi_degree,longi_minute;

value1 = lati_value(0)-0x30;

value2 = lati_value(1)-0x30;

lati_degree = value1*10+value2;

value1 = lati_value(2)-0x30;

value2 = lati_value(3)-0x30;

lati_minute = value1*10+value2;

value1 = longi_value(0)-0x30;

value2 = longi_value(1)-0x30;

value3 = longi_value(2)-0x30;

longi_degree = value1*100+value2*10+value3;

value1 = longi_value(3)-0x30;

value2 = longi_value(4)-0x30;

longi_minute = value1*10+value2;

if((lati_degree==28) && (lati_minute==61) && (longi_degree==77) && (longi_minute==23))

{

LCD_cmd(0x01);

LCD_write_string("It's a Delhi");

delay_5sec ;

}

else if((lati_degree==26) && (lati_minute==92) && (longi_degree==75) && (longi_minute==82))

{

LCD_cmd(0x01);

LCD_write_string("It's a Jaipur");

delay_5sec ;

}

else if((lati_degree==23) && (lati_minute==03) && (longi_degree==72) && (longi_minute==58))

{

LCD_cmd(0x01);

LCD_write_string("It's a Ahmedabad");

delay_5sec ;

}

else if((lati_degree==18) && (lati_minute==97) && (longi_degree==72) && (longi_minute==82))

{

LCD_cmd(0x01);

LCD_write_string("It's a Mumbai");

delay_5sec ;

}

else if((lati_degree==23) && (lati_minute==25) && (longi_degree==77) && (longi_minute==41))

{

LCD_cmd(0x01);

LCD_write_string("It's a Bhopal");

delay_5sec ;

}

else if((lati_degree==22) && (lati_minute==56) && (longi_degree==88) && (longi_minute==36))

{

LCD_cmd(0x01);

LCD_write_string("It's a Kolkata");

delay_5sec ;

}

else if((lati_degree==12) && (lati_minute==96) && (longi_degree==77) && (longi_minute==56))

{

LCD_cmd(0x01);

LCD_write_string("It's a Bengaluru");

delay_5sec ;

}

else if((lati_degree==13) && (lati_minute==8) && (longi_degree==80) && (longi_minute==27))

{

LCD_cmd(0x01);

LCD_write_string("It's a Channai");

delay_5sec ;

}

}

int main(void)

{

P2=0x00; //LCD_DATA port as out put port

P3=0x0F; //ctrl as out put

init_LCD; //initialization of LCD

LCD_write_string("GPS DEMO");

LCD_cmd(0xC0);

LCD_write_string(" using AT89C51");

init_USART ; // initialization of USART

while(1)

{

value=usart_getch ;

if(value=='$')

{

value=usart_getch ;

if(value=='G')

{

value=usart_getch ;

if(value=='P')

{

value=usart_getch ;

if(value=='R')

{

value=usart_getch ;

if(value=='M')

{

value=usart_getch ;

if(value=='C')

{

value=usart_getch ; while(value!=',') // wait upto next ","

{ value=useart_getch ; } value=usart_getch ;

while(value!=',') // wait upto next ","

{

value=usart_getch ;

} value=usart_getch ; while(value!=',') // wait upto next ","

{

value=usart_getch ;

} lati_value(0) = user_getch ;

value = lati_value(0);

for(t=1;value!=',';t++)

{

lati_value

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.