Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to convert hex value(16 bit) to ascii to display on lcd

Status
Not open for further replies.

mathus

Newbie level 6
Joined
Aug 29, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,338
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)......
 

Re: convert hex to ascii.......

What language do you use ? C or Assembler?
 

Re: convert hex to ascii.......

i am using asm language..
 

Re: convert hex to ascii.......

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".

Brian.
 

Re: convert hex to ascii.......

Code:
void hex_to_ascii(unsigned char display_data)
{
	unsigned char temp;
	temp = ((display_data & 0xF0)>>4);
	if (temp <= 0x09)
		putc(temp+'0');	
	else
		putc(temp+'0'+0x07);

	temp = display_data & 0x0F;
	if (temp <= 0x09)
		putc(temp+'0');	
	else
		putc(temp+'0'+0x07);

}
 

Re: convert hex to ascii.......

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.

Brian.
 

Re: convert hex to ascii.......

Code:
void hex_to_ascii(unsigned char display_data)
{
	unsigned char temp;
	temp = ((display_data & 0xF0)>>4);
	if (temp <= 0x09)
		putc(temp+'0');	
	else
		putc(temp+'0'+0x07);

	temp = display_data & 0x0F;
	if (temp <= 0x09)
		putc(temp+'0');	
	else
		putc(temp+'0'+0x07);

}

Hello Jestin_cubetech,
Can you post your putc function please.
I didn't get the lines :

"putc(temp+'0');" &

"putc(temp+'0'+0x07);"
 

Re: convert hex to ascii.......

Code:
Uc = PIC16F877A
compiler Hi tech - c
------------------------------------
void putc(chr)
{
 TXREG=chr; while(!TRMT);
}
 

Re: convert hex to ascii.......

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..........
 

Re: convert hex to ascii.......

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.

Brian.
 

Re: convert hex to ascii.......

Hi everyone,
Can u provide me the code to convert the hex to ascii in C language???
 

Re: convert hex to ascii.......

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.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top