0

I am trying to extract data of Lat and Long sent by GPS module to the 8051uC.

GPS received data looks like:

$GPRMC,062637.000,A,2253.49272,N,07258.83129,E,,,270212,,,A*6970212,0.1,W,A*12

I need to write in the LCD the LAT and LONG,

I started the code by MikriC compiler from an example but sounds it is incompleted


char uart_rd;  
sbit LCD_RS at P2_0_bit;  
sbit LCD_EN at P2_1_bit;  

sbit LCD_D4 at P2_2_bit;  
sbit LCD_D5 at P2_3_bit;  
sbit LCD_D6 at P2_4_bit;  
sbit LCD_D7 at P2_5_bit;  

char idata info[70];  
char test[]="$GPGGA";  
unsigned int check=0,i;  
unsigned char a;  
int j;  
void main() {  
  Lcd_Init();  

  UART1_Init(4800);               // Initialize UART module at 4800 bps,  
                                  // receiver enabled  
                                  //frame size 8 bits  
                                  //1 STOP bit  
                                   //parity mode disabled  
                                   //disabled automatic address recognition  

  Delay_ms(100);                  // Wait for UART module to stabilize  


  while (1) {  

    if (UART1_Data_Ready() == 1) { // if data is received  
    UART1_Read_Text(info, "$GPGGA", 10); // reads text until '$GPRMC' is found  
      LCD_Out(1,1,info);  
    }  Delay_ms(1000);  
  }  
}

Elia
  • 37
  • 1
  • 8
  • use a state machine and walk through the sentence, dont think of it as a string. OR collect a string from $ until you find another then check the checksum/crc and then parse it. I have always used a state machine for this and that makes it pretty easy. – old_timer Nov 16 '19 at 22:52
  • IIRC there will be "\r\n" at the end of the string so you might like to use/implement some kind of `gets()`. *Note: `gets()` is considered unsafe, better use `fgets()` as template.* – the busybee Nov 17 '19 at 09:01

0 Answers0