PIC Microcontoller Radix Math Method

10bit to BCD unpacked 4 digit in 38 inst ~88 cycles by E. A. Grens

10 bit Binary to BCD Conversion

Posted on the Chat Zone by Ed Grens on September 22, 2004 at 03 08 38

On 18 September Peter Hemsley posted a 12b binary to BCD conversion subroutine in a response to a post by me. His algorithm is excellent for 12b conversion, but not efficient for the 10b often encountered with A/D inputs. Over the 10b data range, 0x000 to 0x3FF, this routine requires on the average of 131 processor cycles. Actually this is more than it requires on the average over the entire 12b range (118 cycles).

A simple divide by power of ten algorithm, listed below, requires on the average 88 cycles over the 10b range. This is possible because, for 10b, one can use single byte subtractions for divides. At 12b (probably) and certainly at 16b this approach cannot compete with the procedure Peter has presented. But, if 10b is what you need, it can be advantageous.

Ed

Code:

See also:

Comments:

Michael Lee Van Dyke Says:

On the 10 bit code, the 9th instruction after the Bin2decg label is is "goto B2d2". There is no B2d2 label in the code, it will not work as it is written here.

Questions: