jeb Posted April 12, 2007 Report Share Posted April 12, 2007 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 becauseit doesn't work (i can't do _mulint work, etc. becauseeven 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 Quote Link to comment Share on other sites More sharing options...
jeb Posted April 13, 2007 Author Report Share Posted April 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
Wilba Posted April 13, 2007 Report Share Posted April 13, 2007 Turn the number into BCD (binary coded decimal) i.e.12345 -> 0x01 0x23 0x45then 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] Quote Link to comment Share on other sites More sharing options...
jeb Posted April 13, 2007 Author Report Share Posted April 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
Wilba Posted April 13, 2007 Report Share Posted April 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
stryd_one Posted April 14, 2007 Report Share Posted April 14, 2007 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.