View previous topic :: View next topic |
Author |
Message |
giopic
Joined: 26 Aug 2009 Posts: 4 Location: Padova - Italy
|
binary to decimal conversion |
Posted: Sun Mar 21, 2010 2:36 pm |
|
|
I want to show on an LCD a number resulting from an A/D conversion or from several operations.
The result of A/D conversion is 10 bits long, coming from a PIC16F876 A/D converter.
The operations give me a 16 bits number.
I need to converts these binary numbers in decimal to send to LCD.
How can I convert a binary number to a decimal one ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 21, 2010 4:08 pm |
|
|
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
|
|
Posted: Mon Mar 22, 2010 11:12 am |
|
|
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
|
|
|
|