hii everybody..
iam working on rpm measurment of a motor in this i want to convert hex value(16 bit)to ascii to disply on lcd.....
plz help me .............( any demo code or any suggestion)......
Tou haven't told us what processor so this is the general idea:
1. take the high 4 bits of the hex number by ANDing with 0xF0 then shift the result to the right 4 times. The high bits should now be in the low bits.
2. if the number is > 9, add 7 to it.
3. add 0x30 to it. The result is the high 4 bits as ascii.
4. AND the original hex digit with 0x0F to isolate the lower 4 bits.
5 repeat steps 2 and 3 to convert thelower bits to ascii.
This will convert 0x00 through 0xFF into "00" to "FF".
Which is more or less as I stated but the request was for assembly language not 'C'. The principle is the same but the code in the previous post can be shorter.
thanks a lot sir for helping..
sir one more problem in my project i am geting a big digit like(0fffh) which is greater than 16 bit then how to convert it in ascii..
i am usig 8051mc..........
Same principle, isolate each digit in turn by ANDing with 0xF000, 0x0F00, 0x00F0 then 0x000F then shift the bits right so the four active bits are in the lowest position. Then if the number is > 9 add 7 to it to jump over the gap between '9' and 'A' in the ascii table. Finally add 0x30 (or character zero '0') to the result so the value zero aligns with the ascii character zero.
You are resurecting an old thread but the instructions are still the same. You can only convert one 4-bit value at a time so use something like this:
Code:
//*******************************************************************************
// convert a binary value to it's equivalent ascii hex character
unsigned char BinToAsc(unsigned char BinValue)
{
BinValue &= 0x0F;
if(BinValue > 9) BinValue += 7;
return(BinValue + '0');
}
If you need to convert values greater than 0x0F, mask the bits for each hex digit, shift them to the lowest 4 bits then call the routine, it will return the equivalent ASCII character.