CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Reading ADC value and display on flex LCD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Shaheers



Joined: 23 Sep 2013
Posts: 14

View user's profile Send private message

Reading ADC value and display on flex LCD
PostPosted: Sat Nov 02, 2013 4:16 am     Reply with quote

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: 19267

View user's profile Send private message

PostPosted: Sat Nov 02, 2013 4:32 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group