We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi I have done the analog to digital conversion in lpc2138.the thing is i need to display the digital data in lcd . the adc data will be in hex format (0x1FD) and that will be stored in the data register on adc . in order to display that using character lcd the HEX data has to be converted in to ASCII . i dont know how to do that. coding is done in c using keil tool.
Thanks in advance
Hexadecimal?
No - the processor just stores values. It isn't until _you_ decide to precent values on a display that you may decide to make the precentation in binary, octal, decimal, hexadecimal or whatever. Inside the processor it's a number.
Same with the source code. You may write a constant as 0x17 or 23 or 021 - but the compiler will take care of converting it to "just a number" before making use of it.
So your task, when displaying that ADC value is to convert it from "just a number" into a decimal number (individual digits in range 0..9) and then convert these digits into ASCII ('0' .. '9').
Guesss what. There are at least a hundred answers on this specific forum about how to do it. There are many, many, many thousands of answers reachable using Google.
If you can afford the code size of sprintf(), the task is trivial. If not, it is still very easy if you think about / (division) and % (modulo). That will help figuring out the individual decimal digits - adding '0' to each digit is enough to get an ASCII representation.
Hi Per Westermark
The data present in the adc data register is like this (0x000003A2)just as example.
a = 0x000003A2; b = a%10; b = b+0; a = a/10; c = a%10; c = c+0; a = a/10; a = a+0; is that correct ?
thanks
a = 0x000003A2; b = a%10; b = b+0x30; a = a/10; c = a%10; c = c+0x30; d = a/10; d = d+0x30;
i tried by adding '0' but even that was not working thanks
Interesting that you write "even that was not working".
Even what? Your first attempt did add the value zero - and your math book already told you that addition zero to a number isn't expected to do any big magic.
Your second attempt you added 0x30 - you can write '0' instead unless you find it too readable to use actual characters.
But the big question is: you say it isn't working. But you don't say what is happening and what you expected to happen.
a = 0x000003A2; // = 930 decimal b = a%10; // = 0 decimal b = b+0x30; // = '0' a = a/10; // = 93 decimal c = a%10; // = 3 decimal c = c+0x30; // = '3' d = a/10; // = 9 decimal d = d+0x30; // = '9'
You unhappy with '9' '3' and '0'?