this program neoGps Starter kit please help me
 
 
 
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.5a Advanced
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
 
Project : 
Version : 
Date    : 3/27/2012
Author  : David Suryadinata, L3
Company : Innovative Electronics
Comments: 
 
 
Chip type               : ATmega8535
Program type            : Application
AVR Core Clock frequency: 4.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 128
*****************************************************/
 
#include <mega8535.h>
#include <delay.h>
//#include <ctype.h>
#include <string.h>
 
// Standard Input/Output functions
#include <stdio.h>
 
// Declare your global variables here
#define Pulse PORTA.0
#define RTS PORTD.4
#define CTS PIND.5
#define TM PIND.2
#define RST PORTD.3
#define WU PIND.6
#define OO PORTD.7
 
#define msg0 "$PSRF100,1,4800,8,1,0*" //SER
#define msg1 "$PSRF103,05,00,00,01*" //VTG
#define msg2 "$PSRF103,04,00,00,01*" //RMC
#define msg3 "$PSRF103,03,00,00,01*" //GSV
#define msg4 "$PSRF103,02,00,00,01*" //GSA
#define msg5 "$PSRF103,00,00,03,01*" //GGA 3 sec
#define msg6 "$PSRF114,1b,1,3,1,a,0,0,0,f,6,0,f0,0,0,4a,0*"
//#define msg7 "$PSRF103,08,00,00,01*" //ZDA
 
unsigned char msg[27], kode[6], jam[2], menit[2], detik[2], lati[9], ns, longi[10], ew, sat[2], alti[5];
unsigned char cksum, grup, xcount;
unsigned char cksumcalc[2];
bit valid, star, sto, paket=0;//, elcm=0, ots=0;
void checksum(void);
void checksumfly(void);
 
void inituart(void);
void txsend(unsigned char datatx);
         
#ifndef RXB8
#define RXB8 1
#endif
 
#ifndef TXB8
#define TXB8 0
#endif
 
#ifndef UPE
#define UPE 2
#endif
 
#ifndef DOR
#define DOR 3
#endif
 
#ifndef FE
#define FE 4
#endif
 
#ifndef UDRE
#define UDRE 5
#endif
 
#ifndef RXC
#define RXC 7
#endif
 
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
 
// USART Receiver buffer
#define RX_BUFFER_SIZE 80
char rx_buffer[RX_BUFFER_SIZE];
 
#if RX_BUFFER_SIZE <= 256
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif
 
// This flag is set on USART Receiver buffer overflow
bit rx_buffer_overflow;
 
// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data, xuart;
status=UCSRA;
data=UDR;
 
   //txsend(data);//
 
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
   {
   rx_buffer[rx_wr_index++]=data;
#if RX_BUFFER_SIZE == 256
   // special case for receiver buffer size=256
   if (++rx_counter == 0) rx_buffer_overflow=1;
#else
 
   if (data == 0x24)//$
      {
      grup = 0;
      valid = 1;
      star = 1;
      sto = 0;
      //msg[0] = 0;
      xcount = 0;
      //txsend(data);//
      }
   else if (data == 0x2C)//,
      {
      if (grup == 0)
         {
         if ((msg[0] != 'G')||(msg[1] != 'P')||(msg[2] != 'G')||(msg[3] != 'G')||(msg[4] != 'A')) valid = 0;
         xuart=0;
         do
            {
            kode[xuart] = msg[xuart];
            xuart++;
            } while (xuart<5);
         //if ((msg[0] == 'P')&&(msg[1] == 'S')&&(msg[2] == 'R')&&(msg[3] == 'F')&&(msg[4] == '1')&&(msg[5] == '5')&&(msg[6] == '6')) elcm=1;
         //if ((msg[0] == 'P')&&(msg[1] == 'S')&&(msg[2] == 'R')&&(msg[3] == 'F')&&(msg[4] == '1')&&(msg[5] == '5')&&(msg[6] == '0')) ots=1;
         }
      else if (grup == 1)//utc
         {
         jam[0] = msg[0];
         jam[1] = msg[1];
         menit[0] = msg[2];
         menit[1] = msg[3];
         detik[0] = msg[4];
         detik[1] = msg[5];
         }
      else if (grup == 2)//latitude
         {
         xuart=0;
         do
            {
            lati[xuart] = msg[xuart];
            xuart++;
            } while (xuart<9);
         }
      else if (grup == 3)//N/S
         {
         ns = msg[0];
         }
      else if (grup == 4)//longitude
         {
         xuart=0;
         do
            {
            longi[xuart] = msg[xuart];
            xuart++;
            } while (xuart<10);
         }
      else if (grup == 5)//E/W
         {
         ew = msg[0];
         }
      else if (grup == 6)
         {
         if (msg[0] == 0x30) valid = 0;
         }
      else if (grup == 7)
         {
         if ((msg[0] == 0x30)&&(msg[1] == 0x30)) valid = 0;
         sat[0] = msg[0];
         sat[1] = msg[1];
         }
      else if (grup == 9)
         {
         alti[0] = msg[0];
         alti[1] = msg[1];
         alti[2] = msg[2];
         if (xcount>3) alti[3] = msg[3];; else alti[3]=0x2C;
         if (xcount>4) alti[4] = msg[4]; else alti[4]=0x2C;
         }
 
      //msg[0] = 0;
      xcount = 0;
      grup++;
      }
   else if (data == 0x2A)//*
      {
      sto = 1;
      //msg[0] = 0;
      xcount = 0;
      }
   else if (data == 0x0D)
      {
      checksumfly();
      if ((cksumcalc[0] == msg[0])&&(cksumcalc[1] == msg[1]))
         {
         //txsend(data);//
         }
      else
         {
         valid = 0;
         }
      }
   else if (data == 0x0A)
      {
      paket = 1;
         //txsend(0xAA);//
         //txsend(0x55);//
      rx_wr_index=0;
      rx_counter=0;
      xcount=0;
      //txsend(data);//
      }
   else
      {
      msg[xcount] = /*msg + Chr*/(data);
      xcount++;
      if (star == 1) cksum = data;
      else if (sto == 0) cksum = cksum ^ data;
      star = 0;
      }
   
   
   if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
   if (++rx_counter == RX_BUFFER_SIZE)
      {
      rx_counter=0;
      rx_buffer_overflow=1;
      }
#endif
   }
}
 
#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(void)
{
char data;
while (rx_counter==0);
data=rx_buffer[rx_rd_index++];
#if RX_BUFFER_SIZE != 256
if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#endif
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif
 
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
// Place your code here
Pulse = ~Pulse;
//txsend('+');
}
 
void checksumfly(void)
{
   unsigned char msgcount;
 
   msgcount = cksum >> 4;
   if (msgcount <= 9) msgcount = msgcount + 0x30; else msgcount = msgcount + 0x37;
   cksumcalc[0] = /*Chr*/(msgcount);
 
   msgcount = cksum % 16;
   if (msgcount <= 9) msgcount = msgcount + 0x30; else msgcount = msgcount + 0x37;
   cksumcalc[1] = /*(cksumcalc << 8) + Chr*/(msgcount);
}
 
void checksum(void)
{
   unsigned char msgcount;
   unsigned char msgchar;
   unsigned int cksumchar;
   unsigned char tempchar;
   unsigned char msglen;
 
   msgchar = msg[1];
   cksum = /*toascii*/(msgchar);
   msglen = strlen(msg);
   msgcount = 2;
   do
      {
      msgchar = msg[msgcount];
      tempchar = /*toascii*/(msgchar);
      cksum = cksum ^ tempchar;
      msgcount++;
      } while (msgcount != msglen-1);
 
   msgcount = cksum >> 4;
   if (msgcount <= 9) msgcount = msgcount + 0x30; else msgcount = msgcount + 0x37;
   cksumchar = /*chr*/(msgcount);
 
   msgcount = cksum & 0x0F;
   if (msgcount <= 9) msgcount = msgcount + 0x30; else msgcount = msgcount + 0x37;
   cksumchar = (cksumchar<<8) + /*chr*/(msgcount);
 
   msg[msglen] = cksumchar >> 8;
   msg[msglen+1] = cksumchar & 0x00FF;
   msg[msglen+2] = 0x0D;
   msg[msglen+3] = 0x0A;   
}
 
void main(void)
{
// Declare your local variables here
unsigned char x;
unsigned int y;
 
delay_ms(300);
 
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=1 
PORTA=0x01;
DDRA=0x01;
 
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
//PORTB=0x00;
//DDRB=0x00;
 
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;
 
// Port D initialization
// Func7=Out Func6=In Func5=In Func4=Out Func3=Out Func2=In Func1=Out Func0=In 
// State7=0 State6=P State5=P State4=1 State3=1 State2=P State1=1 State0=P 
PORTD=0x7F;
DDRD=0x9A;//0xAA;
 
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
 
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
 
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
 
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x03;
MCUCSR=0x00;
GIFR=0x40;
 
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
 
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 4800 (Double Speed Mode)
UCSRA=0x02;
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x67;
 
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
 
// ADC initialization
// ADC disabled
ADCSRA=0x00;
 
// SPI initialization
// SPI disabled
SPCR=0x00;
 
// TWI initialization
// TWI disabled
TWCR=0x00;
 
inituart();
 
//delay_ms(1000);
 
if (CTS==1)//if (RTS==1)
   {
   txsend('C');//
   txsend('T');//
   txsend('S');//
   txsend(0x0D);//
   txsend(0x0A);//
   }
 
if (WU==0)
   {
   txsend('S');//
   txsend('L');//
   txsend('1');//
   txsend(0x0D);//
   txsend(0x0A);//
   }
 
 
while (WU==0)
   {
   OO=0;
   delay_ms(700);
   OO=1;
   delay_ms(200);
   OO=0;
   delay_ms(700);
   }
 
   txsend('W');//
   txsend('U');//
   txsend('1');//
   txsend(0x0D);//
   txsend(0x0A);//
 
RTS=0;//CTS=0;
 
while (WU==1)
   {
   OO=0;//RST=1;//OO=0;
   delay_ms(700);
   OO=1;//RST=0;//OO=1;
   delay_ms(200);
   OO=0;//RST=1;//OO=0;
   delay_ms(700);
   }
 
   txsend('S');//
   txsend('L');//
   txsend('2');//
   txsend(0x0D);//
   txsend(0x0A);//
 
while (WU==0)
   {
   OO=0;
   delay_ms(1200);
   OO=1;
   delay_ms(200);
   OO=0;
   }
 
   txsend('W');//
   txsend('U');//
   txsend('2');//
   txsend(0x0D);//
   txsend(0x0A);//
/*
while (CTS==1)//while (RTS==1)
   {
   txsend('R');//
   }
*/
x=0;
do
   {
   msg[x]=msg0[x];
   x++;
   } while (msg[x-1]!=0);
checksum();
puts(msg);
delay_ms(200);
 
x=0;
do
   {
   msg[x]=msg1[x];
   x++;
   } while (msg[x-1]!=0);
checksum();
puts(msg);
delay_ms(200);
 
x=0;
do
   {
   msg[x]=msg2[x];
   x++;
   } while (msg[x-1]!=0);
checksum();
puts(msg);
delay_ms(200);
 
x=0;
do
   {
   msg[x]=msg3[x];
   x++;
   } while (msg[x-1]!=0);
checksum();
puts(msg);
delay_ms(200);
 
x=0;
do
   {
   msg[x]=msg4[x];
   x++;
   } while (msg[x-1]!=0);
checksum();
puts(msg);
delay_ms(200);
 
x=0;
do
   {
   msg[x]=msg5[x];
   x++;
   } while (msg[x-1]!=0);
checksum();
puts(msg);
delay_ms(200);
/*
x=0;
do
   {
   msg[x]=msg7[x];
   x++;
   } while (msg[x-1]!=0);
checksum();
puts(msg);
delay_ms(200);
*/
// Global enable interrupts
#asm("sei")
 
   //txsend('O');//
   //txsend('K');//
 
while (1)
   {
   // Place your code here
   if (paket==1)
      {
      delay_ms(100);
/*      if (elcm == 1)
         {
         txsend('E');//
         txsend('L');//
         txsend('C');//
         txsend('M');//
         txsend(0x0D);//
         txsend(0x0A);//
         x=0;
         do
            {
            msg[x]=msg6[x];
            x++;
            } while (msg[x-1]!=0);
         checksum();
         puts(msg);
         elcm=0;
         }
      else if (ots == 1)
         {
         txsend('O');//
         txsend('k');//
         txsend('T');//
         txsend('S');//
         txsend(0x0D);//
         txsend(0x0A);//
         ots=0;
         }
      else*/ if (valid == 0)
         {
         txsend('E');
         txsend('r');
         txsend('r');
         txsend('o');
         txsend('r');
         txsend(0x0D);
         txsend(0x0A);
         }
      else
         {
         txsend('T');
         txsend('i');
         txsend('m');
         txsend('e');
         txsend(' ');
         txsend(' ');
         txsend(' ');
         txsend(' ');
         txsend(' ');
         txsend(':');
         txsend(' ');
         txsend(jam[0]);
         txsend(jam[1]);
         txsend(':');
         txsend(menit[0]);
         txsend(menit[1]);
         txsend(':');
         txsend(detik[0]);
         txsend(detik[1]);
         txsend(0x0D);
         txsend(0x0A);
         
         txsend('L');
         txsend('a');
         txsend('t');
         txsend('i');
         txsend('t');
         txsend('u');
         txsend('d');
         txsend('e');
         txsend(' ');
         txsend(':');
         txsend(' ');
         x = 0;
         do
            {
            txsend(lati[x]);
            if (x==1) txsend(0xBA);
            if (x==3) txsend(0x27);
            x++;
            } while (x<4);
         y = ((lati[5]-0x30)*1000) + ((lati[6]-0x30)*100) + ((lati[7]-0x30)*10) + ((lati[8]-0x30));
         y = 0.6 * y;
         lati[5] = y / 1000;
         lati[6] = (y % 1000) / 100;
         lati[7] = (y % 100) / 10;
         lati[8] = (y % 10);
         x = 5;
         do
            {
            txsend(0x30+lati[x]);
            if (x==6) txsend(0x2E);
            x++;
            } while (x<9);
         txsend(0x22);
         
         txsend(' ');
         txsend(ns);
         txsend(0x0D);
         txsend(0x0A);
         
         txsend('L');
         txsend('o');
         txsend('n');
         txsend('g');
         txsend('i');
         txsend('t');
         txsend('u');
         txsend('d');
         txsend('e');
         txsend(':');
         txsend(' ');
         x = 0;
         do
            {
            txsend(longi[x]);
            if (x==2) txsend(0xBA);
            if (x==4) txsend(0x27);
            x++;
            } while (x<5);
         y = ((longi[6]-0x30)*1000) + ((longi[7]-0x30)*100) + ((longi[8]-0x30)*10) + ((longi[9]-0x30));
         y = 0.6 * y;
         longi[6] = y / 1000;
         longi[7] = (y % 1000) / 100;
         longi[8] = (y % 100) / 10;
         longi[9] = (y % 10);
         x = 6;
         do
            {
            txsend(0x30+longi[x]);
            if (x==7) txsend(0x2E);
            x++;
            } while (x<10);
         txsend(0x22);
 
         txsend(' ');
         txsend(ew);
         txsend(0x0D);
         txsend(0x0A);
 
         txsend('A');
         txsend('l');
         txsend('t');
         txsend('i');
         txsend('t');
         txsend('u');
         txsend('d');
         txsend('e');
         txsend(' ');
         txsend(':');
         txsend(' ');
         x = 0;
         do
            {
            if (alti[x]!=0x2C) txsend(alti[x]);
            x++;
            } while (x<5);
         txsend(' ');
         txsend('m');
         txsend(0x0D);
         txsend(0x0A);
 
         txsend('S');
         txsend('a');
         txsend('t');
         txsend('e');
         txsend('l');
         txsend('l');
         txsend('i');
         txsend('t');
         txsend('e');
         txsend(':');
         txsend(' ');
         x = 0;
         do
            {
            txsend(sat[x]);
            x++;
            } while (x<2);
         txsend(0x0D);
         txsend(0x0A);
 
         }
      paket = 0;
      }
   }
}

 

GroG

10 years 10 months ago

Dedy, we have a language problem, and I can understand that.

But, I think there is a problem - you ask for help with hardware I have no knowledge about.  Your asking for help with programs which at the moment have nothing to do with this sites software (MyRobotLab).

At this point I would appreciate it if you would stop posting requests for help that are not related to MyRobotLab.

Thank you.

Dedy_hidayat

10 years 10 months ago

Ok thanks Grog