• 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

kawauso

New Member
I would like to know how to write :
1) a message like « Bonjour ! Ça va ? »
2) the value of a variable after measuring,
3) the combination of both 1) & 2) like 3,47 volts.
I made some research on the web. I do not want to use only in MikroC the Conversion Library of Mikroelektronika and the void IntToString(void) without being able to watch the code inside and understanding the conversion process.
Some body has a idea or the link to an open source ?
Thanks at all !
Merci à tous.
Eric
 

Pommie

Well-Known Member
Most Helpful Member
The standard C library is itoa() (integer to ascii). I found this page which implements itoa() in C++ but easy to convert.

Mike.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
Here's mine. No comments .. takes an array, a value and a decimal requirement then stores as fixed point number ie.. 900 with 1 decimal = 90.0
It does what I want it to... modify as you see fit..

C:
void printFloat(char * flt, long number, char digits)
    {
    if(number < 0)
        {
        number = abs(number);
        }
    if(digits == 2)
        {
        flt[0] = number / 1000 + 48;
        if(flt[0] == 48) flt[0] = 0x20;
        flt[1] = ((number % 1000) / 100)+ 48;
        flt[2] = 46;
        flt[3] = ((number % 100) / 10)+ 48;
        flt[4] = (number % 10) + 48;
        flt[5] = 0;
        }
    else
        {
        flt[0] = number / 100 + 48;
        if(flt[0] == 48) flt[0] = 0x20;
        flt[1] = ((number % 100) / 10)+ 48;
        flt[2] = 46;
        flt[3] = (number % 10) + 48;
        flt[4] = 0;
        }
    }
 

AtomSoft

Well-Known Member
Just wondering .. does sprintf work ok micros? I could have sworn I used it before...

NameVariable = Jason
floatDegrees = 78.8
sprintf(buffer, "Hello, %s , it is %f degrees F.", NameVariable,FloatDegrees);

Something like that... Would print

Hello Jason, it is 78.8 degrees F.

Or am I forgetting something :)
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Just wondering .. does sprintf work ok micros? I could have sworn I used it before...

NameVariable = Jason
floatDegrees = 78.8
sprintf(buffer, "Hello, %s , it is %f degrees F.", NameVariable,FloatDegrees);

Something like that... Would print

Hello Jason, it is 78.8 degrees F.

Or am I forgetting something :)
Of course it works, as long as you have a routine to actually do the printing - which you need to write yourself for whatever 'display' you're using.

However, what you're forgetting is the huge impact of sprintf which takes a LOT of memory space, and runs pretty slowly - it's far more efficient to write a specific routine to do just what you want.
 

Mike - K8LH

Well-Known Member
I hate to admit it, but, it's so much easier in Arduino. I added an "LCD" class for my old 2-pin 8-bit LCD Backpack a couple years ago and it was relatively easy to include the Arduino "Print" class for all those neat formatting capabilities... I posted the demo' here on ETO...

Arduino LCD + Print Class demo
 

Nigel Goodwin

Super Moderator
Most Helpful Member
I hate to admit it, but, it's so much easier in Arduino. I added an "LCD" class for my old 2-pin 8-bit LCD Backpack a couple years ago and it was relatively easy to include the Arduino "Print" class for all those neat formatting capabilities... I posted the demo' here on ETO...

Arduino LCD + Print Class demo
Isn't it just a wrapper around sprintf anyway?, and just as resource hungry.

And of course you have the added advantage of C++ rather than plain C.
 

Latest threads

EE World Online Articles

Loading

 
Top