unsigned char gps_header[]="GPRMC,";
I am not familiar with PIC16F628a, and XC8 but I would like to see your code It may be give basic ideaI'll share how I do it, with my PIC16F628a, and XC8..
void main(void)
{
TMOD = 0x20; /* timer1 in mode 2, 8-bit reload */
TH1 = 0xFD; /* Load timer value for 9600 baudrate */
SCON = 0x50; /* SERIAL MODE 1 ,8- BIT DATA ,1 STOP BIT ,1 START BIT , RECEIVING ON */
IE = 0x93; /* Enable serial interrupts
TR1 = 1; /*start timer 1*/
while (1)
{
/* do nothing */
}
}
void serial_IT(void) interrupt 4
{
if(RI == 1)
{
RI = 0;
data = SBUF; //Read received data
}
}
#define MAX_SENTENCE_LENGTH 20 // minimum characters needed to get sentence we want
#define CR '\x0d' // carriage return
#define LF '\x0a' // line feed
unsigned char CharIn,ix; // temp CharIn, array index
bit NewSentenceAvailable; // 0 = reading characters from UART to build sentence
// 1 = new sentence built into array
bit BuildingString; // 1 = found $, load chars into array
unsigned char GPSmsg[MAX_SENTENCE_LENGTH+1]; // one more for /0
void interrupt(void)
{
if(RI==1){ // iff character is received..
temp = SBUF; // always read and save it
RI=0; // and clear interrupt flag
// 0 means we don't have a complete one yet.. 1 means main is processing it so ignore all chars
// '$' means start a new string. Ends when array is full OR found end of line
// Note that if you only care about one specific message, you don't have to look for end of line,
// short messages will just restart the loading of the array and the string won't be reported.
// Only strings that have enough characters to be candidates for processing are flagged.
// Main can take as long as it wants to process a string, all incoming characters are ignored until
// main clears NewSentenceAvailable.
if(!NewSentenceAvailable){ // main is not processing so process UART chars
if(!BuildingString){
if(temp == '$'){ // look for '$' to start the sentence, can come at any time
ix = 0; // found '$', start building string on next char
BuildingString = 1;
}
}
else{
GPSmsg[ix++]=CharIn; // save character in buf, bump index
// end of line or full buf?
if((CharIn == CR) || (CharIn == LF) || (ix == MAX_SENTENCE_LENGTH)){
GPSmsg[ix]= '\0'; // terminate it for printing
NewSentenceAvailable = 1; // flag main and stop loading characters here
BuildingString = 0;
}
}
}// taking characters
}// receive interrupt
}// interrupt
// MAIN: wait for a complete sentence to be received. Process it.
void main(void)
{
NewSentenceAvailable = 0; // set up for first string
BuildingString = 0;
ix = 0;
init_stuff();
while(1){
if(NewSentenceAvailable){
if((strncmp("GPGSV",GPSmsg,5)==0){ // if found GPGSV
// process GPGSV message, extract lat and lon etc.
}
if((strncmp("GGA",GPSmsg,3)==0){ // if found GGA
// process GGA message, extract lat and lon etc.
}
NewSentenceAvailable = 0; // clear the flag to tell interrupt routine
// to start another string
} // while
}//main
void gps ()
{
unsigned int LAT[9], LON[10];
unsigned char Temp, i;
if (rx_data() == ‘$’)
{
if( rx_data() == ‘G’)
{
if (rx_data() == ‘P’)
{
if (rx_data() == ‘R’)
{
if (rx_data() == ‘M’)
{
if (rx_data() == ‘C’)
{
while (rx_data() != ‘,’);
while (rx_data() != ‘,’);
/*checking for “A” condition*/
Temp = rx_data();
if (Temp == ‘A’||Temp == ‘V’)
{
while (rx_data() != ‘,’);
/*latitude values*/
LCDCmd (0x80);
for (i=0; i<9; i++)
{
LAT[i] = rx_data();
LCDData (LAT[i]);
}
while (rx_data() != ‘,’);
while (rx_data() != ‘,’);
/*longitude values*/
LCDCmd (0xc0);
for (i=0; i<10; i++)
{
LON[i] = rx_data();
LCDData (LON[i]);
}
}
}}}}}}
}