Sunday, 25 June 2017

GPS Send Data to LCD using AVR

GPS Send Data to LCD using AVR:


#define F_CPU 8000000UL
#include <util/delay.h>
#define rs 0
#define rw 1
#define en 2

#include <avr/io.h>
#include <avr/interrupt.h>
#include<string.h>

//#include"serial_header.h"
//function declaration
void recgps(void);
void delay(int);
void cmden();
void lcdcmd(char);
void lcdinit(void);
void daten(void);
void lcddata(char);
void txdata(char);
unsigned char rxu0(void);
void serial_init();

static unsigned char lat[10];
static unsigned char lon[11];
unsigned char maps_link[50]="www.maps.google.com/";


void cmnd()
{
PORTB&=(~(1<<rs));
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(50);
PORTB&=(~(1<<en));
}
void lcdcmd(char ch)
{
PORTB=ch & 0xf0;
cmnd();
PORTB=(ch<<4) & 0xf0;
cmnd();
}
void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void data()
{
PORTB|=(1<<rs);
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(50);
PORTB&=(~(1<<en));
}
void lcddata(char ch)
{
PORTB=ch & 0xf0;
data();
PORTB=(ch<<4) & 0xf0;
data();
}
void lcdstring(char *str)
{
while(*str)
{
lcddata(*str);
str++;
}
}


void serial_init()
{

UCSRB=0x18;
UCSRC=0x86;
UBRRL=0X33;
}
char uart_read()
{
while(!(UCSRA & (1<<RXC)));
return UDR;
}

void txstring(char *str)
{
while(*str)
{
txdata(*str);
str++;
_delay_ms(20);
}
}


void txdata(char ch)
{
UDR=ch;
while(!(UCSRA & (1<<UDRE)));
_delay_ms(10);
}

void recgps()
{
unsigned char p;
int gps=0;
int i;

while(gps==0)
{
p=uart_read();
while(p!='$')
{
p=uart_read();
}
p=uart_read();
if(p=='G')
{
}
else
continue;
p=uart_read();
if(p=='P')
{
}
else
continue;

p=uart_read();
if(p=='G')
{
}
else
continue;

p=uart_read();
if(p=='G')
{
}
else
continue;

p=uart_read();
if(p=='A')
{
while(p!=',')
{
p=uart_read();
}
p=uart_read();
while(p!=',')
{
p=uart_read();
}
for(i=0;i<9;i++)
{
lat[i]=uart_read();
}
p=uart_read();
while(p!=',')
{
p=uart_read();
}
p=uart_read();
while(p!=',')
{
p=uart_read();
}
for(i=0;i<10;i++)
{
lon[i]=uart_read();
}
lat[9]='\0';
lon[10]='\0';
gps=0;
}
else
continue;
}
}

int main()
{
int i;
DDRB=0XFF;
lcdinit();
serial_init();

lcdcmd(0x80);
lcdstring("Send on LCD ");


  lcdcmd(0x01);
  lcdstring(" Ready... ");
  while(1)
{

lcdcmd(1);
recgps();
lcdstring("Lat:");
lcdstring(lat);
lcdcmd(0xc0);
lcdstring("Lon:");
lcdstring(lon);
_delay_ms(3000);
}

}

Circuit Diagram:




0 comments:

Post a Comment

if you have any doubt please let me know