Jump to content

print a number with a formatting on LCD


jeb
 Share

Recommended Posts

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

Link to comment
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]

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...