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 CCS Technical Support

undefined identifier ADCON0bits... & ADCON1bits?

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



Joined: 27 May 2015
Posts: 8

View user's profile Send private message

undefined identifier ADCON0bits... & ADCON1bits?
PostPosted: Mon Jun 08, 2015 10:53 pm     Reply with quote

How to declare the adc adcon & adcon1 registers in the header file?
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Tue Jun 09, 2015 1:50 am     Reply with quote

#byte ADCON1=getenv("SFR:ADCON1")

Then ADCON1 is a byte variable, that can be accessed like any other. Same syntax for ADCON0.

However, 'why'?.

Generally needing to access a register directly is a sign of not actually writing CCS code.

I repeat what I said in line 2 of my reply to your question about setting the clock:

"2) Don't. Let CCS handle the selections for you. For 99.9% of things you never need to touch a register in CCS."

The way to set the clock in CCS, is simply:
Code:

    setup_adc(ADC_CLOCK_DIV_32); //Choose division according to clock rate


The compiler knows which registers it has to access to set the ADC clock, and does so.

If you look in the data sheet for 'possible clock rates', and then look at the header file for your chip, you will see a 1:1 correspondence between the options offered, and the data sheet options.

Similarly with setup_adc_ports, and which pins can be selected, and which voltage references can be used. So to just select AN0, using the supply as Vref:
Code:

   setup_adc_ports(AN0);


However to use the same pin with external VrefH & VrefL:
Code:

   setup_adc_ports(AN0_VREF_VREF);


The defined names, will remind you in the future, what you were doing, while a number written to the ADCON registers _won't_. Come back in six months time, and try to work out what you were doing, and using the CCS functions will suddenly seem like having been a very good idea.

You have the CCS compiler, so _use_ it.
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