Sign in to follow this  
Followers 0
jeb

print a number with a formatting on LCD

6 posts in this topic

hello,

i have a  unsigned int  that i want  to put on the LCD like this :

500 ->  "5.00"

1253 -> "12.53"

12 -> "0.12"

how to do this ? with the dot as a character...

i don't want to use any div 100 or modulo 100 because

it doesn't work (i can't do _mulint work, etc. because

even if i include this file, the problem is "__gptrget1 or something like that)

i don't manage to use the classical C sprintf / printf functions that would be useful here !

(i have put the include stdio.h)

when linking, the linker says :

missing definition for symbol "_sprintf" required by....

thanx in advance,

jeb

Share this post


Link to post
Share on other sites

hello,

even if it worked, printf is too big for the simple need i have.

so my problem is simply :

how to do a division par 10 or 100 ?

(in order to isolate the different numbers in decimal writing!)

(asm optimized?)

thanx

Share this post


Link to post
Share on other sites

Turn the number into BCD (binary coded decimal) i.e.

12345 -> 0x01 0x23 0x45

then print out each nibble (four bits).

This is actually how it is done in MIOS (but in assembler). The "if"s remove the leading zeros. Anyway, if you know what printf is, you don't need any more help than this  ;D


    unsigned int x = 12345;

    MIOS_HLP_Dec2BCD(x);

    if ( MIOS_PARAMETER3 >> 4 )
        MIOS_LCD_PrintBCD1( MIOS_PARAMETER3 >> 4 );
    else
        MIOS_LCD_PrintChar('.');

    if ( MIOS_PARAMETER3 & 0x0f )
        MIOS_LCD_PrintBCD1( MIOS_PARAMETER3 & 0x0f );
    else
        MIOS_LCD_PrintChar('.');

    if ( MIOS_PARAMETER2 >> 4 )
        MIOS_LCD_PrintBCD1( MIOS_PARAMETER2 >> 4 );
    else
        MIOS_LCD_PrintChar('.');

    MIOS_LCD_PrintBCD1( MIOS_PARAMETER2 & 0x0f );

    MIOS_LCD_PrintChar('.');

    MIOS_LCD_PrintBCD1( MIOS_PARAMETER1 >> 4 );
    MIOS_LCD_PrintBCD1( MIOS_PARAMETER1 & 0x0f );
[/code]

Share this post


Link to post
Share on other sites

thanks a lot Wilba !!!

but MIOS_HLP_Dec2BCD brings me wrong value in MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3...

for example for x=100  (unsigned int)

PAR2 = 0x56 ??

PAR3 = 0x00 ???

that's strange !

i've read a previous post about issues about Dec2BCD but i didn't really understand what was the conclusion !!

thx,jeb

Share this post


Link to post
Share on other sites

I just noticed a bug in my code... the first two MIOS_LCD_PrintChar('.'); should be MIOS_LCD_PrintChar(' ');

MIOS_HLP_Dec2BCD is what is used for all the MIOS_LCD_PrintBCD* functions, so it should work, if it does not then something else is wrong, maybe byte ordering?

Perhaps try MIOS_HLP_Dec2BCD and then MIOS_LCD_PrintHex to dump the BCD values for a range of inputs, try to find out how it is wrong.

Share this post


Link to post
Share on other sites

i've read a previous post about issues about Dec2BCD but i didn't really understand what was the conclusion !!

There was a bug in the wrapper but it's fixed now... Are you using tho latest version of the wrapper?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0