I'm currently working on a traffic monitoring system that requires that geological coordinates (which were like float) are sent as a string through the GSM / GPRS module as a text message. I used the following code to convert these floating point values ββto strings, but in the compilation "warning: (1393) a possible overflow of the hardware stack was detected, apparently the estimated stack depth pops up: 10". I am 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);
}
}
source
share