How to avoid in my project PIC16f877A with floating point to string conversion?

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);
    }
}
+4
source share
1

"sprintf", - ( ok pic16f1705 pic):

char array[64];
float myvalue=2.0f;
sprintf(array, "%f", myvalue);

XC8, help- > XC8 Toolchain- > MPLAB XC8 Compiler- > - > sprintf

USART1 printf:

printf("my message to GSM transitter %f", myvalue); 
+1

All Articles