You are on page 1of 2

#include<avr/io.

h>
#define F_CPU 16000000UL
#define BAUDRATE 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUDRATE * 16UL))) - 1)
#include<avr/delay.h>
unsigned char value,i,lati_value[15],lati_dir, longi_value[15], longi_dir ;
char k[50];


void serial_init() // usart initialization function
{
UBRR0H = (unsigned char)(BAUD_PRESCALLER>>8); // typecasting can also be done in uint8_t
UBRR0L = (unsigned char)(BAUD_PRESCALLER);
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
UCSR0C = (3<<UCSZ00);
}
unsigned char usart_getch() // to get data from GPS module
{

while ((UCSR0A & (1 << RXC0)) == 0); // Do nothing until data have been recieved and is ready to be read from UDR
return(UDR0); // return the byte
}
void send_string(char * str) // to send data to GSM module
{
unsigned char shifts, length;
length = strlen(str);
for(shifts = 0; shifts < length; shifts++)
{
while(!(UCSR0A & (1<<UDRE0))); // condition to check if previous data bit is sent
UDR0 = str[shifts]; // to send data
}
}
void send_MSG()
{

char j;
for(j=0;j<10;j++)
{
_delay_ms(1000);
send_string("AT\r");
}
_delay_ms(1000);
send_string("AT+CMGF=1\r");
_delay_ms(1000);
send_string("AT+CSCS=\"GSM\"\r");
_delay_ms(1000);
send_string("AT+CMGS=\"+919460357448\"\rrequired data is:\n"); // enter your mobile number
send_string(k); // this is complete data to send
_delay_ms(3);
UDR0=26;
}


int main()
{
serial_init(); // initialization of USART
while(1)
{send_MSG();
_delay_ms(1000);
_delay_ms(1000);
_delay_ms(1000);
_delay_ms(1000);
_delay_ms(1000);
_delay_ms(1000);
send_MSG();
value=usart_getch();
if(value=='$')
{
value=usart_getch();
if(value=='G')
{
value=usart_getch();
if(value=='P')
{
value=usart_getch();
if(value=='G')
{
value=usart_getch();
if(value=='G')
{
value=usart_getch();
if(value=='A')
{
value=usart_getch();
if(value==',')
{
value=usart_getch();
while(value!=',')
{
value=usart_getch();
}
lati_value[0]=usart_getch();
value=lati_value[0];
for(i=1;value=',';i++)
{
lati_value[i]=usart_getch();
value=lati_value[i];
}
lati_value[i]='\0';
lati_dir=usart_getch();
value=usart_getch();
while(value!=',')
{
value=usart_getch();
}
longi_value[0]=usart_getch();
value=longi_value[0];
for(i=1;value!=',';i++)
{
longi_value[i]=usart_getch();
value=longi_value[i];
}
longi_value[i]='\0';
longi_dir=usart_getch();
int j,y;
for( j=0;lati_value[j]!='\0';j++)
k[j]=lati_value[j];
k[j]=lati_dir;
for( y=j+1;longi_value[y-j-1]!='\0';y++)
k[y]=longi_value[y-j-1];
k[y]=longi_dir;
k[y+1]='\0';
send_MSG();
}
}
}
}
}
}
}
}
}

You might also like