Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC > LCD > Displaying string and int value

Status
Not open for further replies.
I've been messing.. My routine probably wont do what you need... You will need the "dirty" Ftoa() then you can see whats happening, once you know you can switch to sprintf..

C:
char * ftoa(float f, int * status)
{
    static char        buf[17];
    char *            cp = buf;
    unsigned long    l, rem;

    if(f < 0) {
        *cp++ = '-';
        f = -f;
    }
    l = (unsigned long)f;
    f -= (float)l;
    rem = (unsigned long)(f * 1e6);
    sprintf(cp, "%lu.%6.6lu", l, rem);
    return buf;
}

I have used this and its good enough to view whats going on..
 
I've been messing.. My routine probably wont do what you need... You will need the "dirty" Ftoa() then you can see whats happening, once you know you can switch to sprintf..

C:
char * ftoa(float f, int * status)
{
    static char        buf[17];
    char *            cp = buf;
    unsigned long    l, rem;

    if(f < 0) {
        *cp++ = '-';
        f = -f;
    }
    l = (unsigned long)f;
    f -= (float)l;
    rem = (unsigned long)(f * 1e6);
    sprintf(cp, "%lu.%6.6lu", l, rem);
    return buf;
}

I have used this and its good enough to view whats going on..
Merci Ian,
Will try and understand. But unfortunately I think sprintf doesn’t run on PIC 16F ... Will switch soon to 18 F ...
 
All three are available to you... You have to select them ( separately ) from the library manager.
1632327764978.jpeg


They are normally not included.. When the compiler asks "include all libraries" you would have said no..
 
All three are available to you... You have to select them ( separately ) from the library manager.
View attachment 133807

They are normally not included.. When the compiler asks "include all libraries" you would have said no..
Merci.
I already used this way while trying to run a former code with sprintf with 16F877 and 887. Could only use sprintl or sprinti.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top