Microcontroller › AVR › How to program a ATmega16 with GPS (basic)? › CODE VIII:#include
March 31, 2013 at 4:25 am
#9400
sushant
Participant
CODE VIII:
#include <avr/io.h>
BRiCS
Page
7
#include <avr/interrupt.h>
#include <util/delay.h>
char status = 0,index = 0,lat[10] = ” “,lon[10] = ” “;
char sat[2] = “**”,dop[4] = “****”,tim[6] = “******”;
ISR(USART_RXC_vect){
unsigned char c;
c = UDR;
if (c==’$’){status = 1;index = 0;}
else if((index == 3)&(c != ‘G’)) status=0;
else if((index == 4)&(c != ‘G’)) status=0;
else if(index> 6 & index< 13)tim[(index- 7)]=c;
else if(index>17 & index< 27)lat[(index-18)]=c;
else if(index>30 & index< 40)lon[(index-31)]=c;
else if(index>44 & index< 47)sat[(index-45)]=c;
else if(index>46 & index< 51)dop[(index-47)]=c;
if(status==1)
index++;
}
int main(void) {
set_uartbaud(9600);
enable_uart_rxcint();
LCDinit();
LCDclr();
sei();
while (1) {
_delay_ms(200);
LCDGotoXY(0,0);
LCDstring(lat,10);
LCDstring(sat,2);
LCDstring(dop,4);
LCDGotoXY(0,1);
LCDstring(lon,10);
LCDstring(tim,6);
}
}