I have GPS data, convert LAT&LON, display on LCD good, but trouble saving values

Thread Starter

chillcat

Joined Jan 23, 2018
15
pic18f4520, mplab xc8. I redid my gps coding and I using an interrupt for each gps receive. My original plan was to convert the data into usable values (googlemap) (29.xxxxxx,-83.xxxxxx) and send sms. I have just that showing up on LCD, but I need to recall these exact converted figures to resend SMS (located right after the LCD function). I'm trying to store lat and lon into their own buffers/arrays, but having slight difficulty. If you scroll down to bottom where I convert the lat and lon values you'll see I'm trying to store the value into buffer (See LAT), LON), at top I have char LAT[9], char LON[10]. Trying to display the LAT data on line 4 in my while loop I'm only getting "2" which is 1st # in that data, what am I doing wrong ?



C:
#define _XTAL_FREQ 8000000
#define GGA_buf_Size 80
#define GGA_Pointers_Size 20
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <math.h>
#include <string.h>
#pragma config BOREN=ON,CPD=OFF,OSC=INTIO7,WDT=OFF
void LCDinit(), LCDcmd(int unicorn), LCDstring(char *unicorn), LCDdata(int unicorn);
char UART_Init(const long int baudrate),UART_Read(),UART_Data_Ready();
void UART_Data(char data), UART_String(char *text), SMS(void), GPS_get(void), Delay_Ms(unsigned int delay);
float LON_Convert(float raw), LAT_Convert(float raw),GPS_LON(unsigned char LON_pointer), GPS_LAT(char LAT_pointer);
void TIME_Convert(unsigned long int UTC_Time);
unsigned long int GPS_Time();
void UART_Data(char data), UART_String(char *text);
unsigned char i, GPGGA_point[GGA_Pointers_Size]; // stores the comma instances;
char GPGGA_buf[GGA_buf_Size], GPGGA_code[3], COMMA_i, Data_buf[15];
LAT[9];                              // SAVE these for SMS
LON[10];
volatile unsigned int GPGGA_i;
volatile unsigned char GPGGA_string = 0;
void interrupt GPS_Retrieve();

char UART_Init(const long int BAUD){
unsigned int x;
x = (_XTAL_FREQ - BAUD*64)/(BAUD*64);
if(x>255){x = (_XTAL_FREQ - BAUD*16)/(BAUD*16),BRGH = 1;}
if(x<256){SPBRG = x,SYNC = 0,SPEN = 1,TRISC7 = 1,TRISC6 = 1,CREN = 1,TXEN = 1;
return 1;}
return 0;}

int main(){
ADCON1 = 0b00001111; // sets A to digital only
OSCCON = 0x72; // Internal Clock 8Mhz
TRISA = 0b00111100; // LED A0 (r),A1 (g)
TRISB = 0b11111111; // Interrupts B0,B1
TRISD = 0b01100000; // LCD: E-D7,RS-D4, Data-3:0
TRISC = 0b11111111;

Delay_Ms(10);

UART_Init(9600);

LCDinit();
LCDcmd(0x80),LCDstring(" TEAM UNICORN "),LCDcmd(0xC0),LCDstring("My Horse is Amazing"),LCDcmd(0x94);
LCDstring(""),LCDcmd(0xD4),LCDstring("Searching Satellites");
Delay_Ms(2000);
LCDcmd(0x01);

while(1){
char GPS_buf[15];
char GPS_lat_final[9];
unsigned long int Time;
float Latitude,Longitude;
float final;

INTCONbits.GIE=1,INTCONbits.PEIE=1,PIE1bits.RCIE=1; // Interrupt ON
Delay_Ms(1000); // 1 sec to gather data
INTCONbits.GIE=0,INTCONbits.PEIE=0,PIE1bits.RCIE=0; // Interrupt OFF

LCDcmd(0x80), LCDstring("UTC: ");
Time = GPS_Time(), TIME_Convert(Time);
LCDstring(Data_buf);

LCDstring(" ");

LCDcmd(0xc0);

LCDstring("LAT: ");
Latitude = GPS_LAT(GPGGA_point[0]);
Latitude = LAT_Convert(Latitude);

sprintf(GPS_buf,"%.06f",Latitude); // 6 decimal rounding after .
LCDstring(GPS_buf);

LCDstring(" ");
GPS_lat_final[i] = GPS_buf[i];

LCDcmd(0x94);

LCDstring("LON: ");
Longitude = GPS_LON(GPGGA_point[2]);
Longitude = LON_Convert(Longitude);

sprintf(GPS_buf,"%.06f",Longitude);
LCDstring(GPS_buf);

LCDstring(" ");

LCDcmd(0xd4),LCDdata(GPS_lat_final[i]); // I want to view the SAME data that I'm displaying on LCD on line 4
// so I know it's ready to send in SMS

// Delay_Ms(1000);
// UART_String("AT\r\n");
// Delay_Ms(1000);
// UART_String("AT+CMGF=1\r\n");
// Delay_Ms(1000);
// UART_String("AT+CMGS=");
// Delay_Ms(100);
// UART_String("\"");
// Delay_Ms(100);
// UART_String("1352xxxxxxx");
// Delay_Ms(100);
// UART_String("\"");
// Delay_Ms(100);
// UART_String("\r\n");
// Delay_Ms(1000);
// UART_String("http://maps.google.com/maps?q=");
// Delay_Ms(500);
// UART_String(LAT);
// UART_String(",");
// UART_String(LON);
// UART_String("\r\n");
// Delay_Ms(1000);
// UART_Data(0x1A);
// Delay_Ms(30000);

// Delay_Ms(5000);

}
}
void interrupt GPS_Retrieve(){
if(RCIF){GIE = 0; // Disable Global Interrupt
unsigned char RX_data = RCREG;
if(RCSTAbits.OERR){
if (OERR){CREN=0,CREN=1;}
CREN=1;}
if(RX_data =='$'){GPGGA_i = 0, GPGGA_string = 0, COMMA_i = 0;}
else if(GPGGA_string == 1){ /* if true save GGA info. into buffer */
if(RX_data == ',' ) GPGGA_point[COMMA_i++] = GPGGA_i; // Store comma instances into buffer
GPGGA_buf[GPGGA_i++] = RX_data;}
else if(GPGGA_code[0] == 'G' && GPGGA_code[1] == 'G' && GPGGA_code[2] == 'A'){
GPGGA_string = 1, GPGGA_code[0] = 0; GPGGA_code[1] = 0; GPGGA_code[2] = 0;}
else{GPGGA_code[0] = GPGGA_code[1]; GPGGA_code[1] = GPGGA_code[2]; GPGGA_code[2] = RX_data;}}}

unsigned long int GPS_Time(){
unsigned char i, TIME_buf[15];
unsigned long int TIME;
for(i = 0;GPGGA_buf[i]!=','; i++){ TIME_buf[i] = GPGGA_buf[i];}
TIME= atol(TIME_buf); // converting time string to an integer */
return TIME;}

void UART_Data(char data){
while (!TXIF); // Wait for empty transmit buffer
TXREG = data;} // EUSART Transmit Register (loading data into)

void UART_String(char *text){ // send out data characters
while (*text) // loop until we reach a NULL
UART_Data(*text++);} //send character and bump pointer

float GPS_LAT(char LAT_point){
unsigned char LAT_i = LAT_point+1, i = 0;
char LAT_buf[15];
float LATT;
for(;GPGGA_buf[LAT_i]!=',';LAT_i++){ LAT_buf[i]= GPGGA_buf[LAT_i], i++;}
LATT = atof(LAT_buf); // converting LAT sring to an integer
return LATT;}

float GPS_LON(unsigned char LON_point){
unsigned char LON_i, i = LON_point+1;
char LON_buf[15];
float LONG;
LON_i=0;
for( ; GPGGA_buf[i]!=','; i++){ LON_buf[LON_i]= GPGGA_buf[i], LON_i++;}
LONG = atof(LON_buf); // converting LON string to an integer
return LONG;}

void TIME_Convert(unsigned long int time){
unsigned int hr, min, sec;
hr=(time/10000), min=(time%10000)/100, sec=(time%10000)%100; // extracting parts
sprintf(Data_buf, "%d:%d:%d", hr,min,sec);} // UTC time to buffer

float LAT_Convert(float raw){
float converted;
converted = (float)(long int)((int)((float)((double)raw/100)))+(float)(((float)((double)raw/100)-(int)(float)((double)raw/100))/0.6);
// LAT[i] = converted;
return converted;}

float LON_Convert(float raw){
float converted;
converted = (float)((long int)((int)((float)(-1*((double)raw/100)))))+(float)(((float)(-1*((double)raw/100))-(int)((float)(-1*((double)raw/100))))/0.6);
// LON[i] = converted;
return converted;}
Mod edit: code tag specifier = C
 
Last edited by a moderator:

ericgibbs

Joined Jan 29, 2010
18,767
hi chillcat,
I am sure the guys who have been helping on your Threads would like to know what the problem was, others may get the same problem.
E
 

Picbuster

Joined Dec 2, 2013
1,047
pic18f4520, mplab xc8. I redid my gps coding and I using an interrupt for each gps receive. My original plan was to convert the data into usable values (googlemap) (29.xxxxxx,-83.xxxxxx) and send sms. I have just that showing up on LCD, but I need to recall these exact converted figures to resend SMS (located right after the LCD function). I'm trying to store lat and lon into their own buffers/arrays, but having slight difficulty. If you scroll down to bottom where I convert the lat and lon values you'll see I'm trying to store the value into buffer (See LAT), LON), at top I have char LAT[9], char LON[10]. Trying to display the LAT data on line 4 in my while loop I'm only getting "2" which is 1st # in that data, what am I doing wrong ?



C:
#define _XTAL_FREQ 8000000
#define GGA_buf_Size 80
#define GGA_Pointers_Size 20
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <math.h>
#include <string.h>
#pragma config BOREN=ON,CPD=OFF,OSC=INTIO7,WDT=OFF
void LCDinit(), LCDcmd(int unicorn), LCDstring(char *unicorn), LCDdata(int unicorn);
char UART_Init(const long int baudrate),UART_Read(),UART_Data_Ready();
void UART_Data(char data), UART_String(char *text), SMS(void), GPS_get(void), Delay_Ms(unsigned int delay);
float LON_Convert(float raw), LAT_Convert(float raw),GPS_LON(unsigned char LON_pointer), GPS_LAT(char LAT_pointer);
void TIME_Convert(unsigned long int UTC_Time);
unsigned long int GPS_Time();
void UART_Data(char data), UART_String(char *text);
unsigned char i, GPGGA_point[GGA_Pointers_Size]; // stores the comma instances;
char GPGGA_buf[GGA_buf_Size], GPGGA_code[3], COMMA_i, Data_buf[15];
LAT[9];                              // SAVE these for SMS
LON[10];
volatile unsigned int GPGGA_i;
volatile unsigned char GPGGA_string = 0;
void interrupt GPS_Retrieve();

char UART_Init(const long int BAUD){
unsigned int x;
x = (_XTAL_FREQ - BAUD*64)/(BAUD*64);
if(x>255){x = (_XTAL_FREQ - BAUD*16)/(BAUD*16),BRGH = 1;}
if(x<256){SPBRG = x,SYNC = 0,SPEN = 1,TRISC7 = 1,TRISC6 = 1,CREN = 1,TXEN = 1;
return 1;}
return 0;}

int main(){
ADCON1 = 0b00001111; // sets A to digital only
OSCCON = 0x72; // Internal Clock 8Mhz
TRISA = 0b00111100; // LED A0 (r),A1 (g)
TRISB = 0b11111111; // Interrupts B0,B1
TRISD = 0b01100000; // LCD: E-D7,RS-D4, Data-3:0
TRISC = 0b11111111;

Delay_Ms(10);

UART_Init(9600);

LCDinit();
LCDcmd(0x80),LCDstring(" TEAM UNICORN "),LCDcmd(0xC0),LCDstring("My Horse is Amazing"),LCDcmd(0x94);
LCDstring(""),LCDcmd(0xD4),LCDstring("Searching Satellites");
Delay_Ms(2000);
LCDcmd(0x01);

while(1){
char GPS_buf[15];
char GPS_lat_final[9];
unsigned long int Time;
float Latitude,Longitude;
float final;

INTCONbits.GIE=1,INTCONbits.PEIE=1,PIE1bits.RCIE=1; // Interrupt ON
Delay_Ms(1000); // 1 sec to gather data
INTCONbits.GIE=0,INTCONbits.PEIE=0,PIE1bits.RCIE=0; // Interrupt OFF

LCDcmd(0x80), LCDstring("UTC: ");
Time = GPS_Time(), TIME_Convert(Time);
LCDstring(Data_buf);

LCDstring(" ");

LCDcmd(0xc0);

LCDstring("LAT: ");
Latitude = GPS_LAT(GPGGA_point[0]);
Latitude = LAT_Convert(Latitude);

sprintf(GPS_buf,"%.06f",Latitude); // 6 decimal rounding after .
LCDstring(GPS_buf);

LCDstring(" ");
GPS_lat_final[i] = GPS_buf[i];

LCDcmd(0x94);

LCDstring("LON: ");
Longitude = GPS_LON(GPGGA_point[2]);
Longitude = LON_Convert(Longitude);

sprintf(GPS_buf,"%.06f",Longitude);
LCDstring(GPS_buf);

LCDstring(" ");

LCDcmd(0xd4),LCDdata(GPS_lat_final[i]); // I want to view the SAME data that I'm displaying on LCD on line 4
// so I know it's ready to send in SMS

// Delay_Ms(1000);
// UART_String("AT\r\n");
// Delay_Ms(1000);
// UART_String("AT+CMGF=1\r\n");
// Delay_Ms(1000);
// UART_String("AT+CMGS=");
// Delay_Ms(100);
// UART_String("\"");
// Delay_Ms(100);
// UART_String("1352xxxxxxx");
// Delay_Ms(100);
// UART_String("\"");
// Delay_Ms(100);
// UART_String("\r\n");
// Delay_Ms(1000);
// UART_String("http://maps.google.com/maps?q=");
// Delay_Ms(500);
// UART_String(LAT);
// UART_String(",");
// UART_String(LON);
// UART_String("\r\n");
// Delay_Ms(1000);
// UART_Data(0x1A);
// Delay_Ms(30000);

// Delay_Ms(5000);

}
}
void interrupt GPS_Retrieve(){
if(RCIF){GIE = 0; // Disable Global Interrupt
unsigned char RX_data = RCREG;
if(RCSTAbits.OERR){
if (OERR){CREN=0,CREN=1;}
CREN=1;}
if(RX_data =='$'){GPGGA_i = 0, GPGGA_string = 0, COMMA_i = 0;}
else if(GPGGA_string == 1){ /* if true save GGA info. into buffer */
if(RX_data == ',' ) GPGGA_point[COMMA_i++] = GPGGA_i; // Store comma instances into buffer
GPGGA_buf[GPGGA_i++] = RX_data;}
else if(GPGGA_code[0] == 'G' && GPGGA_code[1] == 'G' && GPGGA_code[2] == 'A'){
GPGGA_string = 1, GPGGA_code[0] = 0; GPGGA_code[1] = 0; GPGGA_code[2] = 0;}
else{GPGGA_code[0] = GPGGA_code[1]; GPGGA_code[1] = GPGGA_code[2]; GPGGA_code[2] = RX_data;}}}

unsigned long int GPS_Time(){
unsigned char i, TIME_buf[15];
unsigned long int TIME;
for(i = 0;GPGGA_buf[i]!=','; i++){ TIME_buf[i] = GPGGA_buf[i];}
TIME= atol(TIME_buf); // converting time string to an integer */
return TIME;}

void UART_Data(char data){
while (!TXIF); // Wait for empty transmit buffer
TXREG = data;} // EUSART Transmit Register (loading data into)

void UART_String(char *text){ // send out data characters
while (*text) // loop until we reach a NULL
UART_Data(*text++);} //send character and bump pointer

float GPS_LAT(char LAT_point){
unsigned char LAT_i = LAT_point+1, i = 0;
char LAT_buf[15];
float LATT;
for(;GPGGA_buf[LAT_i]!=',';LAT_i++){ LAT_buf[i]= GPGGA_buf[LAT_i], i++;}
LATT = atof(LAT_buf); // converting LAT sring to an integer
return LATT;}

float GPS_LON(unsigned char LON_point){
unsigned char LON_i, i = LON_point+1;
char LON_buf[15];
float LONG;
LON_i=0;
for( ; GPGGA_buf[i]!=','; i++){ LON_buf[LON_i]= GPGGA_buf[i], LON_i++;}
LONG = atof(LON_buf); // converting LON string to an integer
return LONG;}

void TIME_Convert(unsigned long int time){
unsigned int hr, min, sec;
hr=(time/10000), min=(time%10000)/100, sec=(time%10000)%100; // extracting parts
sprintf(Data_buf, "%d:%d:%d", hr,min,sec);} // UTC time to buffer

float LAT_Convert(float raw){
float converted;
converted = (float)(long int)((int)((float)((double)raw/100)))+(float)(((float)((double)raw/100)-(int)(float)((double)raw/100))/0.6);
// LAT[i] = converted;
return converted;}

float LON_Convert(float raw){
float converted;
converted = (float)((long int)((int)((float)(-1*((double)raw/100)))))+(float)(((float)(-1*((double)raw/100))-(int)((float)(-1*((double)raw/100))))/0.6);
// LON[i] = converted;
return converted;}
Mod edit: code tag specifier = C
After a quick scan: Lat[9] is an char array and converted a float.
179.// LAT = converted;

Again a quick scan

Picbuster
 
Top