View previous topic :: View next topic |
Author |
Message |
ferkar
Joined: 14 Jul 2007 Posts: 38
|
hi everyone from a new user :) |
Posted: Sat Jul 14, 2007 7:07 am |
|
|
dear friend ,this is my first visit to this forum. i would like to ask a question to be answered . ı was trying to read a pot at RA0(analog input) and display the result on a LCD. ı made tehe adc set to 10 bit. however the max value that ı read is 255. so how could i read 10 bit adc result and display on to LCD?
thank you ... |
|
|
ferkar
Joined: 14 Jul 2007 Posts: 38
|
10 bit adc problem? |
Posted: Sat Jul 14, 2007 9:11 am |
|
|
ı thougt about my problem again. and now ı am trying to find that what is the problem exactly.
if ı made the pic16f877 adc setc correctly perhaps LCD could not show 10bit data without a special set. i looked the help file and the examples all shows that 8bit data.
ı am really confused about it.
any help? |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Sat Jul 14, 2007 9:47 am |
|
|
use the preprocessor directive
#device adc=10
and store the value in a 16 bit variable (long or int16) also use the corresponding printf format parameter for the LCD, ...or whatever is your output routine. |
|
|
ferkar
Joined: 14 Jul 2007 Posts: 38
|
thak you for help but... |
Posted: Sat Jul 14, 2007 9:59 am |
|
|
libor ,
ı tried your advice but in that case compiler gives an error like that
" can not change device type this far into the code"
note:my ccs compilerversion is 3.249 |
|
|
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Sat Jul 14, 2007 10:14 am |
|
|
" can not change device type this far into the code"
Then try to change device type not that far in the code :-) Move it to the beginning of the code.
But the problem is, the header file xxxx.h also has a #device line. So I usually place the #device after the #include.
Or you can also edit the one in the header file to include the ADC=10 setiing. |
|
|
ferkar
Joined: 14 Jul 2007 Posts: 38
|
sorry but it did not work |
Posted: Sat Jul 14, 2007 10:45 am |
|
|
added the "device adc=10 " line after include line in the 16f877a header file. the lcd still shows 8 bit value (max 255). here is code that i use maybe it is helpful for you to give an advice:
for(;;)
{
int16 olc,setd;
long int hata;
long int sur;
int kp;
int ki;
long sur_P;
long sur_I;
long al;
long hata_es;
int i;
lcd_init() ;
printf(lcd_putc, "set = %Lu",setd);
set_adc_channel(0);// set
setd=read_adc();
delay_us(25); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ferkar
Joined: 14 Jul 2007 Posts: 38
|
thank you so much:) |
Posted: Sun Jul 15, 2007 9:20 am |
|
|
pcm programmer ,
i made that changes and code worked as ı wish. |
|
|
|