Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] GPS Interface with AVR (ATMEGA 16)

Status
Not open for further replies.

prasantharu

Newbie level 3
Joined
Feb 29, 2016
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
28
I need a code for interfacing GPS with avr(atmega 16) using mikro c program.and please explain the code.
 

Hi,

What code do you need?

Gprs modules often communicate via UART, but it could be any other interface, too.
Code for sending and receiving data with a UART?
Or do you need to know the GPRS commands?

How do you want to process the GPRS data? Storing in memory, showing on a display, transmitting to a PC?

Please give detailed descriptions.
Don't expect the answers to be more detailed than your post (one line: give me code...)

Klaus
 

    V

    Points: 2
    Helpful Answer Positive Rating
Hi,
I need a code for receiving data from the gps module via UART and the data would be show on the LCD Display. I am trying to write the code in mikro c but the problem is that the data cannot be receive properly.
I am using avr microcontroller (ATMEGA 16).
 

Hi,

Your post sounds like: "I need a screw"
With that vague description you will never get the correct screw.

The same is with GPRs modules, displays, interface... there are so many different types ... you need to specify them all.

If you want good help, then you need to provide good informations first. Please not piece by piece.

Klaus
 

Hi,
i m using AVR (ATMEGA 16) microcontroller and GPS MODULE (GPS6MV2) .. My project deals with getting a data that is obtaining latitude and longitude values from the GPS6MV2 module through UART and displaying it on LCD (20*4).. My problem is that i m getting an garbage value for the below code in MIKROC.
Code:
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);
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }

}
for this code i m getting garbage values oly.. if i m using UART_Read() instead of USART_getch i m getting nothing in the display .. i also dont know how to fix the baud rate .. guide me to get the correct latitude and longitude position on lcd display
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top