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 ,.
If I type in characters through serail 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??
If I type in characters through serail 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??
C:
char a, gps[50];
int i, j, k, flag = 0;
void command(char a) //LCD command function
{
char b;
RS = 0;
RW = 0;
PORTB = PORTB & 0X0F;
b = a & 0XF0;
PORTB = PORTB | b;
EN = 1;
__delay_ms(20);
EN = 0;
PORTB = PORTB & 0X0F;
b = a & 0X0F;
b = b << 4;
PORTB = PORTB | b;
EN = 1;
__delay_ms(20);
EN = 0;
}
void data(char a) //LCD dta function
{
char b;
RS = 1;
RW = 0;
PORTB = PORTB & 0X0F;
b = a & 0XF0;
PORTB = PORTB | b;
EN = 1;
__delay_ms(20);
EN = 0;
PORTB = PORTB & 0X0F;
b = a & 0X0F;
b = b << 4;
PORTB = PORTB | b;
EN = 1;
__delay_ms(20);
EN = 0;
}
void display(char *p) //LCD display function
{
while(*p)
{
data(*p);
p++;
}
}
void LCD_init()
{
TRISB = 0X00;
PORTB = 0XFF;
command(0X33);
command(0X32);
command(0X28);
command(0X0C);
command(0X01);
}
void GPS_init()
{
TXSTA = 0X24; //00100100
RCSTA = 0X90; //10010000
SPBRG = 25; //baud rate 9600
}
char uart_rx() //GPS receive function
{
while(!RCIF);
//RCIF=0;
a=RCREG;
return(a);
}
void GPS() //Function to fund require string
{
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(); //Intialize GPS
LCD_init(); //Intialize LCD in 4 bit mode
command(0x80);
display("Initializing");
command(0x01);
GPS();
while(1)
{
command(0XC0);
display(gps);
}
}
Last edited by a moderator: