BCD library

General discussion on mikroC.
Post Reply
Author
Message
gambrose
Posts: 369
Joined: 28 Sep 2004 17:34
Location: uk

BCD library

#1 Post by gambrose » 15 May 2005 18:25

Here is an example of the BCD library I am working on.

http://gambrose.esmartdesign.com/bcd%20library.zip

It includes an example that uses the BCD function to convert a byte to a string in 123 cycles instead of the 1069 cycles it takes the standard library not to shabby I thought (although I dose leave in leading zeros).

To use put BCD16.mcl in the uses/P16 folder of mikroC and P16F877A.mlk in the Defs folder.

Then open the Conversions example project. And have a fiddle.

There are three functions at the moment:

Code: Select all

char Swap(char toSwap);
unsigned long * Int2BCD(unsigned int num);
unsigned * Short2BCD(unsigned short num);
but they only run on the P16 series.

Any comments gratefully received

Note. This is a demonstration and is not for commercial use.
Graham Ambrose

gambrose
Posts: 369
Joined: 28 Sep 2004 17:34
Location: uk

#2 Post by gambrose » 15 May 2005 23:03

I have added two more functions

Code: Select all

unsigned long * Long2BCD(unsigned long num);
unsigned long * Long2BCD_Opt4ROM(unsigned long num);
Long2BCD() will convert to BCD in 1,139 cycles it returns a pointer to a unsigned long as that is the biggest data type allowed but it is in fact a pointer to a char[5] so the top char can be retrieved if wished.

Long2BCD_Opt4ROM() does the same thing but it's a looping version that is optimised for ROM space just 49 compared to 167 for the inline Long2BCD() version but I does take significantly longer to execute at 2,486 cycles.
Graham Ambrose

Post Reply

Return to “mikroC General”