
#include <18F2550.h> 

#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,NOPBADEN,USBDIV,PLL1,CPUDIV1,VREGEN 
#use delay(clock=20M) 
#use rs232(stream=PC, baud=4800, parity=N, bits=8, xmit=PIN_C6, rcv=PIN_C7, ERRORS)  

#include <LCD.C>
#include <STDLIB.H> 
#include <MATH.H> 

char strSentance[6];  // String to hold the sentance name 

#define BUFFER_SIZE 100 
int8 buffer[BUFFER_SIZE]; 
int8 next_in = 0; 
int8 next_out = 0; 

#INT_RDA 
void serial_isr() {       // Serial Interrupt 
   int8 t; 
   buffer[next_in]=getc(); 
   t=next_in; 
   next_in=(next_in+1) % BUFFER_SIZE; 
   if(next_in==next_out) 
     next_in=t;           // Buffer full !! 
} 

#define bkbhit (next_in!=next_out) 

int8 bgetc() { 
   int8 c; 
   WHILE(!bkbhit) ; 
   c=buffer[next_out]; 
   next_out=(next_out+1) % BUFFER_SIZE; 
   return(c); 
} 

void getsentance() { 
strSentance[0] = bgetc(); 
strSentance[1] = bgetc(); 
strSentance[2] = bgetc(); 
strSentance[3] = bgetc(); 
strSentance[4] = bgetc(); 
strSentance[5] = '\0'; 
} 

void main() { 
SETUP_ADC(ADC_OFF); 
   SETUP_ADC_PORTS(NO_ANALOGS); 
   SETUP_COMPARATOR(NC_NC_NC_NC); 
   SETUP_TIMER_0(RTCC_OFF); 
   SETUP_TIMER_1(T1_DISABLED);               // Disable Timer 1 
   SETUP_TIMER_2(T2_DISABLED, 127, 1);       // Disable Timer 2 
   SETUP_TIMER_3(T3_DISABLED);               // Disable Timer 3 
   SETUP_CCP1(CCP_OFF);                      // Disable CCP1 
   SETUP_CCP2(CCP_OFF);                      // Disable CCP2 
   ENABLE_INTERRUPTS(GLOBAL); 
   ENABLE_INTERRUPTS(INT_RDA); 
   
   DELAY_MS(50);
   lcd_init();
   lcd_gotoxy(4,2);
   DELAY_MS(50);
   printf(lcd_putc,"start");
   DELAY_MS(500); 
	 lcd_init();

   while (TRUE) {
         WHILE (bgetc()== '$'){            // Look for a '$' - the start of a NMEA sentence 
                    getsentance();         // Fetch the first 5 characters after the $ , this is the sentance name 
					lcd_gotoxy(10,1); 
					printf(lcd_putc,strsentance); 
		       }                                   
      }  // End While(1) 
   }  // End Main 