![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
roivas
Joined: 28 Jan 2009 Posts: 5
|
ADC question --PIC16F877a, PICDEM 2+ |
Posted: Fri Feb 20, 2009 7:43 pm |
|
|
I am trying to integrate 2 RTD's onto a PICDEM 2+ (Rev. 2002 --Red board) with a 16f877a. I am using the flex_lcd.c LCD driver which uses pins A1:A3, and have a question about configuring the adc using "setup_adc_ports()". All but one of the defines from the header file use at least one of the pins used in the LCD driver. Is there a way to select individual pins and configure them for adc without selecting all the others? I would really like to configure E0:E1 only, but so far I have had no luck with this. I have tried changing the pins' status after using the "setup_adc_ports using set_tris_a, but it still makes the LCD inoperable. I would like to avoid having to multiplex the signals into A0 if possible. Has anyone else had any experience with this sort of thing?
Portions of my code:
Code: | #include <16F877a.H>
#device adc=10//designates 10-bit a/d conversion
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#include "flex_lcd.c"//LCD driver
#include "keypad_init.c"//Keypad driver
#include "menu.c"//Menus
void main()
{
int16 adc_value_faucet,adc_value_tub;
lcd_init();
kbd_init();
setup_adc_ports(AN0);//Tells pin A0 that it will recieve analog input
//setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
//set_tris_a(0x0e);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);//0=RA0/AN0;5=RE0/AN5;6=RE1/AN6
delay_us(20);
//input(PIN_A1);input(PIN_A2);input(PIN_A3);
set_adc_channel(0);//0=RA0/AN0;5=RE0/AN5;6=RE1/AN6**Currently Reads RA0**will be RE0
delay_us(20);
adc_value_faucet = read_adc();//gets a number from the adc
set_adc_channel(6);//READS RE1****this is the part I want to work
delay_us(20);
adc_value_tub=read_adc();
....other code
} |
All of my code works using only A0. I can post the complete code if required, but it is quite long. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 20, 2009 11:10 pm |
|
|
Quote: | Is there a way to select individual pins and configure them for adc without selecting all the others? |
Not with this PIC. The allowable combinations of Analog pins are listed in
the 16F877A.h file. You can't select them individually. Look in this
section:
Quote: | // Constants used in SETUP_ADC_PORTS() are: |
Here's the file location:
Quote: | c:\Program Files\picc\Devices\16f877a.h |
If you want to select individual pins for Analog input, you can do this if
buy a 16F887 chip. It's basically compatible with the 16F877A, but has
several improvements. They should put it in the PicDem2-Plus package
instead of the older PIC.
You can order free samples from Microchip:
http://www.microchip.com/samples/Default.aspx?testCookies=true
If you're in or near the U.S., you can buy it for $2.64 USD with no
minimum order charge (DIP-40 package):
http://www.mouser.com/Search/Refine.aspx?Keyword=579-PIC16F887-I%2fP
There are many other companies worldwide that sell the 16F887. |
|
![](templates/subSilver/images/spacer.gif) |
roivas
Joined: 28 Jan 2009 Posts: 5
|
|
Posted: Sat Feb 21, 2009 7:57 am |
|
|
Thanks for the reply.
I did notice the constants for the setups were groups and that this mirrored the info on the data sheet. I was hoping that there was a way to work around it. I also noticed that the 18F chip that comes with the board has the same adc port setup condition. This would not be a problem on the newer board, where the LCD control lines are on Port D.
The good thing is... the chips are pretty cheap ![Wink](images/smiles/icon_wink.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|