I am currently working on a traffic monitoring system that require Geological coordinates (that are as float) to be sent a string via a GSM/GPRS module as a text message. I used the following code to convert these float values to strings but in compilation "warning: (1393) possible hardware stack overflow detected; estimated stack depth: 10" happens to pop up. I'm using PIC 16f877A and what can I do to avoid this other than changing the MCU ?
void reverse(char *str, int len)
{
int i=0, j=len-1, temp;
while (i<j)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++; j--;
}
}
int intToStr(int x, char str[], int d)
{
int i = 0;
while (x)
{
str[i++] = (x%10) + '0';
x = x/10;
}
while (i < d)
str[i++] = '0';
reverse(str, i);
str[i] = '\0';
return i;
}
void ftoa(float n, char *res, int afterpoint)
{
int ipart = (int)n;
float fpart = n - (float)ipart;
int i = intToStr(ipart, res, 0);
if (afterpoint != 0)
{
res[i] = '.';
fpart = fpart * pow(10, afterpoint);
intToStr((int)fpart, res + i + 1, afterpoint);
}
}