Dibawah ini adalah source code untuk mengakses GPS EM-411 menggunakan Microcontroller ATMega16.
#include <mega16.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <stdio.h>
#include <stdlib.h>
#include <delay.h>
unsigned char data[60];
unsigned char sendx1[5],sendx2[12],sendy1[5],sendy2[12],valid[5];
unsigned char jam[2],menit[2],detik[2],kec[4];
unsigned char tanggal[6],tinggi[4];
int i,ln1,lt1,a,b=0;
float ln2,lt2,speed;
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
TCNT1H=0xD23A >> 6;
TCNT1L=0xD23A & 0xff;
a++;
}
void main(void)
{
TCCR1A=0x00;
TCCR1B=0x04;
TIMSK=0x04;
UCSRA=0x00;
UCSRB=0x10;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x8F;
lcd_init(16);
// Global enable interrupts
#asm("sei")
while (1)
{
valid[0]=' ';
valid[1]=' ';
i=0;
do{
i++;
data[i]=getchar();
valid[1]=data[i];
if(data[i]=='')
break;
if(data[i-4]=='G' && data[i-3]=='P' && data[i-2]=='R' && data[i-1]=='M' && data[i]=='C')
{
i=0;
do{
data[i]=getchar();
valid[1]=data[i];
if(data[i]=='')
break;
i++;
}while(data[i]!=0x0D);
sprintf(kec,"%c%c%c%c",data[39],data[40],data[41],data[42]);
sprintf(sendx1,"%c%c",data[14],data[15]);
sprintf(sendx2,"%c%c%c%c%c%c%c",data[16],data[17],data[18],data[19],data[20],data[21],data[22]);
sprintf(sendy1,"%c%c%c%",data[26],data[27],data[28]);
sprintf(sendy2,"%c%c%c%c%c%c%c",data[29],data[30],data[31],data[32],data[33],data[34],data[35]);
valid[0]=data[12];
if(data[50]==',')
sprintf(tanggal,"%c%c%c%c%c%c",data[51],data[52],data[53],data[54],data[55],data[56]);
if(data[49]==',')
sprintf(tanggal,"%c%c%c%c%c%c",data[50],data[51],data[52],data[53],data[54],data[55]);
sprintf(jam,"%c%c",data[1],data[2]);
sprintf(menit,"%c%c",data[3],data[4]);
sprintf(detik,"%c%c",data[5],data[6]);
}
}while(data[i]!='$');
i=0;
do{
i++;
data[i]=getchar();
valid[1]=data[i];
if(data[i]=='')
break;
if(data[i-4]=='G' && data[i-3]=='P' && data[i-2]=='G' && data[i-1]=='G' && data[i]=='A')
{
i=0;
do{
data[i]=getchar();
valid[1]=data[i];
if(data[i]=='')
break;
i++;
}while(data[i]!=0x0D);
if(data[58]=='M')
sprintf(tinggi,"%c%c%c",data[54],data[55],data[56]);
if(data[57]=='M')
sprintf(tinggi,"%c%c%c%c%c%c",data[53],data[54],data[55]);
}
}while(data[i]!='$');
if(valid[1]=='')
{
data[i]=' ';
valid[0]=' ';
valid[1]=' ';
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("Disconnected");
for(i=12;i<=15;i++)
{
lcd_gotoxy(i,0);
lcd_putsf(".");
delay_ms(800);
PORTC.3=0;
delay_ms(700);
PORTC.3=1;
}
}
if(valid[0]=='V')
{
valid[0]=' ';
valid[1]=' ';
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("Wait");
for(i=4;i<=7;i++)
{
lcd_gotoxy(i,0);
lcd_putsf(".");
delay_ms(800);
PORTC.3=0;
delay_ms(700);
PORTC.3=1;
}
}
if(valid[0]=='A')
{
if(b==0)
{
lt1=atoi(sendx1);
lt2=atof(sendx2);
lt2=(lt2/60)+lt1;
sprintf(sendx2,"%0.6f",lt2);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("Lt: -");
lcd_gotoxy(5,0);
lcd_puts(sendx2);
lcd_gotoxy(15,0);
lcd_putsf("S");
ln1=atoi(sendy1);
ln2=atof(sendy2);
ln2=(ln2/60)+ln1;
sprintf(sendy2,"%0.6f",ln2);
lcd_gotoxy(0,1);
lcd_putsf("Ln: ");
lcd_gotoxy(4,1);
lcd_puts(sendy2);
lcd_gotoxy(15,1);
lcd_putsf("E");
if(a>=5)
{
b=1;
a=0;
}
}
if(b==1)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts(tanggal);
lcd_gotoxy(0,1);
lcd_puts(jam);
lcd_gotoxy(2,1);
lcd_putsf(":");
lcd_gotoxy(3,1);
lcd_puts(menit);
lcd_gotoxy(5,1);
lcd_putsf(":");
lcd_gotoxy(6,1);
lcd_puts(detik);
lcd_gotoxy(8,1);
lcd_putsf(" ");
if(a>=10)
{
b=2;
a=0;
}
}
if(b==2)
{
speed=atof(kec);
speed=speed*1.852;
sprintf(kec,"%0.3f",speed);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("Speed:");
lcd_gotoxy(7,0);
lcd_puts(kec);
lcd_gotoxy(10,0);
lcd_putsf("km/jam");
lcd_gotoxy(0,1);
lcd_putsf("Tinggi:");
lcd_gotoxy(8,1);
lcd_puts(tinggi);
lcd_gotoxy(11,1);
lcd_putsf("meter");
if(a>=5)
{
b=0;
a=0;
}
}
}
};
}