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
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
sprintf(dec_str, "%4d", ADvalue - bias);
That would be 2K more in binaries. We can do better writing out the function. But I am not doing his work for free.
That's assembly code? For what?
Hold on... Let me get my credit card.
Doing something like this manually on the PIC in assembly is going to hurt, real bad.
-Isaac
I survived. 16-bit decimal output routine here,
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.
That should be add 256 and 512.
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
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?
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
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)
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.