18F252 and parsing NMEA
I wrote this test code for an 18F252 to parse the NMEA strings with $ GPRMC header and store them in the internal eeprom to transmit the values detected with the IIC bus when the master requests it.
sorry my awful english
//--------------------------- EXTRACION DATOS ----------------------------------
void Parsing_GPS(char *L_NMEA)
{
unsigned short Fix,N_S,E_W,Delta;
unsigned int Gr_Lat,Min_Lat,Sec_Lat;
unsigned int Gr_Long,Min_Long,Sec_Long;
float Raw_Latitud,Raw_Longitud;
char *Buffer,*Datos[40],strDatos[40];
//CALCULO
Buffer=strtok(L_NMEA,",");
for(Delta=0;Delta<13;Delta++)
{
Datos[Delta]=Buffer;
Buffer=strtok(NULL,",");
}
if(strcmp(Datos[0],"$GPRMC")==0)
{
//FIX
if(strcmp(Datos[2],"A"))Fix=0x00;else Fix=0x01;
WR_Eeprom(0x00,Fix);
//LATITUD
Raw_Latitud=atof(Datos[3]);
Gr_Lat=Raw_Latitud/100;
Min_Lat=Raw_Latitud-(Gr_Lat*100);
Sec_Lat=(Raw_Latitud-((Gr_Lat*100)+Min_Lat))*60;
WR_Eeprom(0x08,Gr_Lat);
WR_Eeprom(0x09,Min_Lat);
WR_Eeprom(0x0A,Sec_Lat/256);
WR_Eeprom(0x0B,Sec_Lat%256);
//LATITUD N_S
if(strcmp(Datos[4],"S"))N_S=0x00;else N_S=0x01;
WR_Eeprom(0x0C,N_S);
//LONGITUD
Raw_Longitud=atof(Datos[5]);
Gr_Long=Raw_Longitud/100;
Min_Long=Raw_Longitud-(Gr_Long*100);
Sec_Long=(Raw_Longitud-((Gr_Long*100)+Min_Long))*60;
WR_Eeprom(0x10,Gr_Long);
WR_Eeprom(0x11,Min_Long);
WR_Eeprom(0x12,Sec_Long/256);
WR_Eeprom(0x13,Sec_Long%256);
//LONGITUD E_W
if(strcmp(Datos[6],"E"))E_W=0x00;else E_W=0x01;
WR_Eeprom(0x14,E_W);
Led_status^=1;
}
}
//--------------------------- CICLO --------------------------------------------
void main(void)
{
Config_PIC();
__delay_ms(100);
while(1)
{
char NMEA[]="$GPRMC,192123.00,V,4056.72626,N,01421.39990,E,0.191,,120121,,,A*7E";
Parsing_GPS(NMEA);
__delay_ms(400);
}
}
[/code]the result is this
EEData Memory
0000 01 FF FF FF FF FF FF FF
0008 28 38 00 2B 00 FF FF FF
0010 0E 15 00 17 01 FF FF FF
0018 FF FF FF FF FF FF FF FF
[/code]however I find the values of the FIX and of the hemispheres and cardinal points reversed
0x00 = 0x01 instead of 0x00("A")
0x0C=0x00 instead of 0x01("N")
0x0C=0x01 instead of 0x00("E")
what am I doing wrong?