I am trying to configure a GPS receiver with PIC16F876A. In the code below i am receiving characters from UART, and checking whether received character is $
. If condition is true, receive characters and store it in character array gps
until ,
is seen.
If I type in characters through serial prompt in Linux, code works as it is supposed to. But if I connect it to the GPS receiver I only get first two characters and LCD will show OVERRUN. I am new to PIC. what should I do??
char a, gps[50];
int i, j, k, flag = 0;
void GPS_init()
{
TXSTA = 0X24; //00100100
RCSTA = 0X90; //10010000
SPBRG = 25;
}
char uart_rx()
{
while(!RCIF);
//RCIF=0;
a=RCREG;
return(a);
}
void GPS()
{
for(i=0; ;i++)
{
a = uart_rx();
TXREG = a; //view received data in serial terminal
while(TRMT == 0);
data(a);
if(OERR == 1)
{
command(0Xc0);
display("OVERRUN"); //Display string to LCD
CREN = 0;
}
if(a == '$')
{
gps[0] = '$';
for(k=1; ;k++)
{
gps[k] = uart_rx();
data(gps[k]); //display character to LCD
TXREG = gps[k]; //view received data in serial terminal
while(TRMT == 0);
if(gps[k] == ',')
{
gps[k] = '\0';
flag = 1;
break;
}
}
}
if(flag == 1)
{
flag = 0;
break;
}
}
}
main()
{
GPS_init();
LCD_init();
command(0x80);
display("Initializing");
command(0x01);
GPS();
while(1)
{
command(0XC0);
display(gps);
}
}