Monday, 16 July 2018

Interfacing GPS(Global Position System) Module to AVR Microcontroller (Atmega-8)


Aim:

A global positioning system (GPS) receiver is used to get precise geographical location by receiving information from satellites. It not only gives information about location but also information like time, date, height and speed. It is so useful that most smartphones are embedded with it.

Description:

GPS receivers have many applications in aircraft, ships, sea vessels and the like for navigation purposes. Smartphones with maps (like Google Maps) find routes to a specific destination such as a restaurant, hospital or hotel. With the help of a GPS, a target camp can be located and a missile launched to destroy it.
Picture
The GPS receiver module includes an antenna and a built-in processor. The built-in processor calculates the required information from the signals’ output serially in form of strings using NMEA (expanded as National Marine Electronics Association) 0183 protocol. These strings are received serially by the host computer for display or by host processor/controller to take any decision or action.






Fig. 2: GPRMC string format
FIG. 2: GPRMC STRING FORMAT

NEMA protocol includes standard messages given by the GPS receiver. Some standard message outputs from NMEA are GGA, ZDA, VTC, RMC, GSA and GSV. The string starts with $GPRMC tag and gives time, latitude, longitude, etc.

Block Diagram

gps

Schematic

gps

Code

// ***************************************************
// Project: Interfacing GPS module with atmega8 
// Author: Hack Projects India 
// Module description: Operate GPS
// ***************************************************
#include <avr/io.h>
#include <util/delay.h>

#define Data PORTB
#define RS_en() PORTB |=(1<<PB4)
#define RS_clr() PORTB &= ~(1<<PB4)
#define E_en() PORTB |=(1<<PB5)
#define E_clr() PORTB &= ~(1<<PB5)

void InitLCD();
void LCDCmd(unsigned char);
void LCDData(unsigned char);
void LCDWriteString(const char *);
void InitLCD()
{
 lcd_cmd(0x02);
 _delay_ms(2);
 lcd_cmd(0X28);
 _delay_ms(2);
 lcd_cmd(0X06);
 _delay_ms(2);
 lcd_cmd(0X01);
 _delay_ms(2);
 lcd_cmd(0X0c);
 _delay_ms(2);
 lcd_cmd(0X80);
 _delay_ms(2);
}
void LCDCmd(unsigned char cmd)
{
 RS_clr();
 E_en();
 _delay_us(100);
 Data|=(cmd>>4);
 _delay_us(100);
 E_clr();
 Data&=~(cmd>>4);
 _delay_us(100);
 E_en();
 _delay_us(100);
 Data|=(cmd&0x0f);
 _delay_us(100);
 E_clr();
 Data&=~(cmd&0x0f);
}
void LCDData(unsigned char dat)
{
 RS_en();
 E_en();
 _delay_us(100);
 Data|=(dat>>4);
 _delay_us(100);
 E_clr();
 Data&=~(dat>>4);
 _delay_us(100);
 E_en();
 _delay_us(100);
 Data|=(dat&0x0f);
 _delay_us(100);
 E_clr();
 Data&=~(dat&0x0f);
 _delay_us(100);
}
void LCDWriteString(const char *str)
{
 while((*str)!='\0')
 {
  LCDData(*str);
  str++;
 }
}
void LCDGotoXY(uint8_t x,uint8_t y)
{
 if(x<40)
 {
  if(y)
  x|=0b01000000;
  x|=0b10000000;
  LCDCmd(x);
  }
}
void LCDClear()
{
 LCDCmd(0x01);
}
void USART_Init()
{
 UBRRL=0x33;
 UCSRB=(1<<TXEN)|(1<<RXEN);
 UCSRC=(3<<UCSZ0)|(1<<UMSEL);
}
unsigned char USART_Receave()
{
 while(!(UCSRA&(1<<RXC)));
 UCSRA=(0<<RXC);
 return UDR;
}
int main(void)
{
 DDRB=0xff;
 int c=0,b;
 unsigned char x,a[]="\0";
 USART_Init();
 InitLCD();
 while(1)
 {
 unsigned int k=6,d=0,y=0,i=0;
 for(b=0;b<6;b++)
 if(USART_Receave()=='$')
 {
 if(USART_Receave()=='G')
 {
 if(USART_Receave()=='P')
 {
 if(USART_Receave()=='R')
 {
 if(USART_Receave()=='M')
 {
 if(USART_Receave()=='C')    
 {
 while(USART_Receave() != ',');
 while(USART_Receave() != ',');
 if(USART_Receave()=='A')
 {
 if(USART_Receave()==',')
 {
 LCDClear();
 LCDWriteString("LATI:");
 LCDCmd(0xc0);
 LCDWriteString("LONG:");
 while(d<4)
 {
 x=USART_Receave();
 if(x!=',')
 {
 LCDGotoXY(k++,y);
 _delay_ms(0.2);
 LCDData(x);
 _delay_ms(0.2);
 }
 else
 {
 d++;
 if(d==2)
 {
 k=6;
 y=1;
 }
 }
 }
 }                                                                                             
 }
 else
 {
 LCDClear();
 LCDWriteStringXY(0,1,"OUT OF CVG");
 _delay_ms(5);
 }
 }
 }
 }
 }
 }
 }                                                         
 }
}

Downloads:

The code was compiled in Atmel Studio 6 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:


No comments:

Post a Comment