Need 10 bit binary to unpacked decimal code for PIC18F Microcontroller.

Can anyone point me to some example assembly code that converts a 10 bit A/D result to a 4 digit decimal value?

Thanks...

SD

Reply to
SD
Loading thread data ...

sprintf(dec_str, "%4d", ADvalue - bias);

Reply to
Everett M. Greene

That would be 2K more in binaries. We can do better writing out the function. But I am not doing his work for free.

Reply to
linnix

That's assembly code? For what?

Reply to
SD

Hold on... Let me get my credit card.

Reply to
SD

Doing something like this manually on the PIC in assembly is going to hurt, real bad.

-Isaac

Reply to
Isaac Bosompem

I survived. 16-bit decimal output routine here,

formatting link

Reply to
toby

A simple lookup table will do the lower 8 bits. A test bit, add 512 if set will do the next bit. Test bit add 1024 if set for the last bit. Not very hard really.

Reply to
cbarn24050

That should be add 256 and 512.

Reply to
cbarn24050

For 10 bits it's not too painful. I wrote a routine that works fine, it's just not that efficient. I'm working on a more compact version now and was wondering what else was out there. I think I'll be content with what I've got / will have on my own. Thanks to toby and cbarn for your contributions to the thread.

SD

Reply to
SD

A/D

Do you have in mind conversion to BCD? In which case a byte lookup would surely only handle 6 bits, leaving 4 to handle by testing and adding?

Reply to
toby

Counting iterations of subtracting of decreasing powers of 10 (i.e.

1000, 100, 10, 1) is a relatively fast and code-economical method.
--
Dan Henry
Reply to
Dan Henry

In this particular case (10 bit number on 8 bit micro), the following method may be more compact:

Repeatedly subtract 100. Store iteration count in one byte, store remainder in other byte. Take these two bytes in turn, and call routine to split each into two digits by repeatedly subtracting 10.

This only involves 8 bit subtractions (in the first step, you'll have to decrement MSB as necessary)

Reply to
Arlet

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.