Shaheers
Joined: 23 Sep 2013 Posts: 14
|
Reading ADC value and display on flex LCD |
Posted: Sat Nov 02, 2013 4:16 am |
|
|
I am using 18F452 and a flex_lcd.c as display driver, all i need to know that how to convert 10 bit ADC value to decimal or as char to display over LCD, because hex value does not showing properly on lcd |
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sat Nov 02, 2013 4:32 am |
|
|
You do not have a hex value.....
Internally you always have binary. This is all the chip understands. If you have lines like:
val=16;
val=0x10;
val=0b00010000;
They are all putting exactly the same number into 'val'. 00010000 binary
You need to convert the internal binary number, into _ASCII_ text.
Look at printf. This formats an internal value, into ASCII text for you to send to anything you want (LCD, serial, etc..).
so (with 'val' above):
printf(lcd_putc,"%02x",val);
will display 'val' as two _hex_ digits. So '10' on the display.
printf(lcd_putc,"%03u",val);
will display val as unsigned decimal, so '16' on the display.
etc. etc. etc...
The bit in inverted commas, is the 'format string', telling the routine how you want the value displayed.
A quick search here, a look at some of the examples (both those with the compiler, and posted here), a look at the manual, and a read of a C textbook, will give some idea of how this works. The one 'special CCS feature' here is being able to 'route' the output directly 'to' a non standard output device (in this case lcd_putc).
Remember also the full ADC value will be more than 8bits, so an int16 variable needed, and then look at the meaning of 'L' in the format string.
Really is very basic C programming, and if you need to ask this, you should be doing some simple C 'exercises' _before_ trying to program the PIC....
Best Wishes |
|