Mark Stokes wrote:
I saw your picture on your web page...
How does that tell you I'm British? You do realise I'm the 3 year old
half-Chinese in that picture, don't you? :-)
Here's my Bin2Bcd4 routine. Compiles to 370 bytes (dec)
I like yours better.
/*******************************************************************
Convert from Binary to BCD
*******************************************************************/
unsigned long int Bin2Bcd4( unsigned long int val )
{
unsigned long int temp = 0;
temp = ( ( val ) % 10 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 4 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 8 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 12 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 16 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 20 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 24 );
val /= 10;
temp += ( ( ( val ) % 10 ) << 28 );
return( temp );
}
Functionally that's now quite the same as mine, as it returns the BCD in
a long, and can overflow. Maybe its enough for what you do, though. My 5
byte return value is a pain to work with, but I needed a full 32 bit range.
More significantly, not having used BCD on the MSP430 before, I never
though to much about it. How do you do BCD subtraction quickly on a 430?
Does anyone, by any chance, have a bunch of BCD functions they would
like to contribute? :-)
Regards,
Steve