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

binary to decimal conversion

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 4:08 pm     Reply with quote

Here is a demo program that shows how to display the decimal ADC
result on an LCD. The ADC value will go from 0 to 1023 as you turn
the trimpot knob.
Code:

#include <16F877.H>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

#include "flex_lcd.c"

//============================
void main()
{
int16 adc_value;
 
lcd_init();

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);

while(1)
  {
   adc_value = read_adc();
   printf(lcd_putc, "\f%4lu", adc_value);
   delay_ms(500);
  }
giopic



Joined: 26 Aug 2009
Posts: 4
Location: Padova - Italy

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 11:12 am     Reply with quote

Thank you very much.
I used it and it works.
I tried to modify it to obtain the voltage too. For this I need to multiply "adc_value" by 5 and divide the result by 1023 and show the result using comma (or point) as decimal separator. But I get only one number (1 to 4). Probably because "int16 adc_value" ?

Can you explain me how I can do it ?

Where can I find manual to learn how to use C language in CCS ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 22, 2010 11:26 am     Reply with quote

This post shows how to convert the ADC value to volts and display it:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
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