prasantharu
Newbie level 3
I need a code for interfacing GPS with avr(atmega 16) using mikro c program.and please explain the code.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
sbit LCD_RS at PORTC5_bit;
sbit LCD_EN at PORTC4_bit;
sbit LCD_D4 at PORTC0_bit;
sbit LCD_D5 at PORTC1_bit;
sbit LCD_D6 at PORTC2_bit;
sbit LCD_D7 at PORTC3_bit;
sbit LCD_RS_Direction at DDC5_bit;
sbit LCD_EN_Direction at DDC4_bit;
sbit LCD_D4_Direction at DDC0_bit;
sbit LCD_D5_Direction at DDC1_bit;
sbit LCD_D6_Direction at DDC2_bit;
sbit LCD_D7_Direction at DDC3_bit;
#define F_CPU 16000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
unsigned char value,lati_value[10],lati_dir, longi_value[11], longi_dir,time[6],IST_time[4],date[6];
unsigned char speed[7],corse_angle[7];
unsigned int t;
void usart_init()
{
UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (3 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
}
unsigned int usart_getch()
{
while ((UCSRA & (1 << RXC)) == 0); // Do nothing until data have been recieved and is ready to be read from UDR
return(UDR); // return the byte
}
void display_latitude()
{ Lcd_Out(1,1,lati_value[0]);
Lcd_Out(1,2,lati_value[1]);
Lcd_Out(1,3,lati_value[2]);
Lcd_Out(1,4,lati_value[3]);
Lcd_Out(1,5,lati_value[5]);
Lcd_Out(1,6,lati_value[6]);
Lcd_Out(1,7,lati_value[7]);
Lcd_Out(1,8,lati_value[8]);
Lcd_Out(1,9,lati_dir);
}
void display_lognitude()
{
Lcd_Out(2,1,longi_value[0]);
Lcd_Out(2,2,longi_value[1]);
Lcd_Out(2,3,longi_value[2]);
Lcd_Out(2,4,longi_value[3]);
Lcd_Out(2,5,longi_value[4]);
Lcd_Out(2,6,longi_value[6]);
Lcd_Out(2,7,longi_value[7]);
Lcd_Out(2,8,longi_value[8]);
Lcd_Out(2,9,longi_value[9]);
Lcd_Out(2,10,longi_dir);
}
void convert_to_IST()
{
unsigned int UTC_hour, UTC_minute,IST_hour,IST_minute,tmp,temp;
UTC_hour = (time[0]-0x30)*10 + (time[1]-0x30);
UTC_minute = (time[2]-0x30)*10 + (time[3]-0x30);
IST_hour = UTC_hour+5;
if(IST_hour>24) IST_hour-=24;
IST_minute = UTC_minute+30;
if(IST_minute>=60)
{
IST_minute-=60;
IST_hour+=1;
}
if(IST_hour>=10)//if(IST_hour>10)
{
tmp=IST_hour%10;
IST_time[1] = tmp+0x30;
temp = IST_hour/10;
IST_time[0] = temp+0x30;
}
else
{
IST_time[0] = 0x30;
tmp=IST_hour%10;
IST_time[1] = tmp+0x30;
}
if(IST_minute>=10)//if(IST_minute>10)
{
tmp=IST_minute%10;
IST_time[3] = tmp+0x30;
temp = IST_minute/10;
IST_time[2] = temp+0x30;
}
else
{
IST_time[2] = 0x30;
tmp=IST_minute%10;
IST_time[3] = tmp+0x30;
}
}
void display_time()
{
Lcd_Out(1,1,"IST-");
convert_to_IST();
Lcd_Out(1,5,IST_time[0]);
Lcd_Out(1,6,IST_time[1]);
Lcd_Out(1,7,":");
Lcd_Out(1,8,IST_time[2]);
Lcd_Out(1,9,IST_time[3]);
Lcd_Out(1,10,":");
Lcd_Out(1,11,IST_time[4]);
Lcd_Out(1,12,IST_time[5]);
}
void display_date()
{
Lcd_Out(2,1,"Date:");
Lcd_Out(2,6,date[0]);
Lcd_Out(2,7,date[1]);
Lcd_Out(2,8,"/");
Lcd_Out(2,9,date[2]);
Lcd_Out(2,10,date[3]);
Lcd_Out(2,11,"/");
Lcd_Out(2,12,date[4]);
Lcd_Out(2,13,date[5]);
}
void display_speed()
{
int i;
Lcd_Out(1,1,"Speed:");
for(i=0;i<5;i++)
{
Lcd_Out(1,8,speed[i]);
}
Lcd_Out(1,9,"knots");
}
void display_corse()
{
int i;
Lcd_Out(2,1,"Direction:");
for(i=0;i<5;i++)
{
Lcd_Out(2,11,corse_angle[i]);
}
}
void main()
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"GPS DEMO");
Lcd_Out(2,1,"Using ATMega16");
Delay_ms(4000);
usart_init(); // initialization of USART
{ value=
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();
if(value==',')
{
time[0] = usart_getch();
value = time[0];
for(t=1;value!=',';t++)
{
time[t] = usart_getch();
value = time[t];
}
value = usart_getch();
while(value!=',') // wait upto next ","
{
value=usart_getch();
}
lati_value[0] = usart_getch();
value = lati_value[0];
for(t=1;value!=',';t++)
{
lati_value[t] = usart_getch();
value = lati_value[t];
}
lati_dir=usart_getch();
value = usart_getch();
longi_value[0] = usart_getch();
value = longi_value[0];
for(t=1;value!=',';t++)
{
longi_value[t] = usart_getch();
value = longi_value[t];
}
longi_dir=usart_getch();
value = usart_getch();
speed[0] = usart_getch();
value = speed[0];
for(t=1;value!=',';t++)
{
speed[t] = usart_getch();
value = speed[t];
}
corse_angle[0] = usart_getch();
value = corse_angle[0];
for(t=1;value!=',';t++)
{
corse_angle[t] = usart_getch();
value = corse_angle[t];
}
date[0] = usart_getch();
value = date[0];
for(t=1;value!=',';t++)
{
date[t] = usart_getch();
value = date[t];
}
Lcd_Cmd(0x01);
Delay_ms(5000);
display_time();
Delay_ms(5000);
display_date();
Delay_ms(5000);
//display_latitude();
//Delay_ms(5000);
//display_lognitude();
display_speed();
Delay_ms(5000);
display_corse();
Delay_ms(5000);
}
}
}
}
}
}
}
}
}