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.

[SOLVED] 16 bit Hex to decimal in C

Status
Not open for further replies.

smuo

Newbie level 5
Joined
Nov 30, 2011
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Bangalore
Activity points
1,354
hi..........
I'm new to embedded, in my project I need convert 16 bit hexadecimal to decimal and need to display it on LCD. please help me.........I'm using at89s51 micro controller.
 

Code:
void lcd_print_value(u32 val)
{
	u8 buffer[10] = {0};
	u8* head = buffer;
	u8 cnt=0;
	if (val!=0)
	{
		while( val )
		{
    		*head++ = (val % 10)["0123456789"];
    		val /= 10;
			cnt++;
		}
		while (cnt!=0){ cnt--; lcd_print_char(buffer[cnt]); }
	}
	else
	{
		lcd_print_char('0');
	}
}
 

sorry.........
i didnt understood yopur code can you please explain me.
 

u8 - unsigned char variable
u32 - unsigned long
what exactly do you want that I explain?
 

hexadecimal number will be stored in an array like dat[]={0x1F,0x38,0xF9}
this should me converted in to decimal and displayed on to LCD.
 

What is the problem to display all elements of array to the screen? Separate them by spaces or some else.
 
  • Like
Reactions: smuo

    smuo

    Points: 2
    Helpful Answer Positive Rating
I think u didnt get wat want friend actually i need to treat that entire array as an hexadecimal string and convert it to decimal then to display it into LCD. that I'm working in micro controller 89s51
 

I think u didnt get wat want friend actually i need to treat that entire array as an hexadecimal string and convert it to decimal then to display it into LCD. that I'm working in micro controller 89s51

the first thin is that u cant send decimal to the LCD, you have to send the ascii value of the decimal number that you want to display

so first of all you have to change the hex to decimal,then separate the digits like, if it is 15 in decimal,you have to separate 1 and 5...then make 1--> 31(hex)..this is the ascii for one send it to lcd and then again make 5-->35(hex)..and again send it to lcd,this will display 15 on lcd
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top