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

Config the AN12 in Pic18f2550

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Config the AN12 in Pic18f2550
PostPosted: Thu May 20, 2010 8:02 am     Reply with quote

Hi, I am use the Pic18F2550 and I need use only the AN12 (RB0) as a analog input and the others ports specifically the RB1 as digital inputs and all others ports as digital outputs, someone can tell me if this configuration is correct or should I change it?

Code:
void main(){

   setup_adc_ports(PIN_B0);
   setup_adc(ADC_CLOCK_DIV_64 );
   set_adc_channel(12);

   SET_TRIS_A (0b00000000);
   SET_TRIS_B (0b00000001);         
   SET_TRIS_C (0b00000000);
    ..........
    .......
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Thu May 20, 2010 8:58 am     Reply with quote

Not correct, and not possible....
You can only use the constants for any function, that are defined _for_ that function. If you look in the include file for the 2550, you will find a section of defines _for_ the setup_adc_ports function.
Now none exist that only configure AN12 as an ADC input. This is not a CCS limitation, but a _chip_ limitation. Read the data sheet.
The _only_ selection, that allows B0, to be used as an analog input, is the 'ALL_ANALOG' selection, enabling every analog input.
A pin that is programmed as an analog input, _can_ still be used for normal output, but at a 'cost'. There is a small amount of crosstalk through the ADC multiplexer, implying that you will find the accuracy of the ADC degraded.
realistically, if you want a single analog input, you _must_ make the connection to AN0.

Best Wishes
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Thu May 20, 2010 2:45 pm     Reply with quote

Hi Ttelmah, thank by your help, but necessarily I can only use the RB0 as analog input.
In these lines of code first configure all analog channels and then just leave the analog channel that interests me and reconfigure all the others as digital outputs, this can work?
Code:

void main(){

   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_DIV_64 );
   set_adc_channel(12);

   SET_TRIS_A (0b00000000);
   SET_TRIS_B (0b00000001);         
   SET_TRIS_C (0b00000000);
    ..........
    .......
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Fri May 21, 2010 2:36 am     Reply with quote

Yes, but with the caveat already given....

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