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

Setting up 1 digital input

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



Joined: 17 Aug 2009
Posts: 50

View user's profile Send private message

Setting up 1 digital input
PostPosted: Wed Aug 19, 2009 10:26 am     Reply with quote

hey, im new to ccs, so sorry about the trivial question.

im playing with my 16f690 chip, and am trying to set pin RC0 to be a digital output. I know that because the chip has a/d convertors, the pin is analog by default.

reading the manual, i decided to use setup_adc_ports(), but when i compile, i get an error.

whats wrong with the following statement, and how can i make it such that only that one pin is digital output and leave the rest alone. surely theres a faster way?

setup_adc_ports( 57_58_59_60_61_62_63_ANALOG); //set RC0 to digital input

the error it gives is that 'expecting a close peren right after 57. I followed the format from the manual, so not sure whats wrong.

please help.

thanks
hobby_85



Joined: 17 Aug 2009
Posts: 50

View user's profile Send private message

PostPosted: Wed Aug 19, 2009 10:44 am     Reply with quote

ahh prolly should have read some other posts. i understand now. its the chip.

but is there a faster way to do it such that just this one pin is digital?

ive had to resort to saying setup_adc_(NO_ANALOG)
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 19, 2009 11:20 am     Reply with quote

There is a bit of confusion in your post. The pins on your PIC that correspond to AN0 to AN9 (channels 0 to 9 of the A/D converter) can be configured as analog INPUTS. If configured as outputs they can only be digital.

The pin C0 is AN4. If you want to drive it high or low you can just use the output_high() and output_low() functions which automatically set this pin as an output without you using the set_up_adc() statement.
bela



Joined: 31 Aug 2008
Posts: 27
Location: Bedford, BEDS UK

View user's profile Send private message Visit poster's website

re Setting up 1 digital input
PostPosted: Wed Aug 19, 2009 11:29 am     Reply with quote

Hi. I don't have the CCS header file for that pic so I can't give any parameters for setup_adc()

In my experience, simply set the port to the digital direction that you want regardless of what the ADC is configured for. so, if you wan't all analogues except pin C0, specify ALL ANALOGS then do output_low(PIN_C0);

There's also the PIC tristate registers you could look at. CCS uses a functions called set_tris_x() where x is the port. You will need to read about FAST_IO before you get into tris.
hobby_85



Joined: 17 Aug 2009
Posts: 50

View user's profile Send private message

Re: re Setting up 1 digital input
PostPosted: Wed Aug 19, 2009 11:36 am     Reply with quote

sorry about the confusion, my bad.

i meant digital INPUT...not output. so i want the 1 pin to be a digital input
bela



Joined: 31 Aug 2008
Posts: 27
Location: Bedford, BEDS UK

View user's profile Send private message Visit poster's website

PostPosted: Wed Aug 19, 2009 11:45 am     Reply with quote

Personally, I'd just do this:

Code:

boolean mydigi;

mydigi=input(PIN_C0);


to get its digital state.[/code]
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 19, 2009 11:48 am     Reply with quote

Look at your header file in the section for setting up the analog inputs. It looks something like this:

Code:

// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS   0x0F   // None
#define ALL_ANALOG   0x00   // A0 A1 A2 A3 A5 B1 B4 B0                   
#define AN0_TO_AN9   0x05   // A0 A1 A2 A3 A5 B1 B4                     
#define AN0_TO_AN8   0x06   // A0 A1 A2 A3 A5 B1                         
#define AN0_TO_AN4   0x0A   // A0 A1 A2 A3 A5
#define AN0_TO_AN3   0x0B   // A0 A1 A2 A3
#define AN0_TO_AN2   0x0C   // A0 A1 A2
#define AN0_TO_AN1   0x0D   // A0 A1
#define AN0          0x0E   // A0


For THIS device (PIC18f2685) the allowed parameters to the set_up_adc() function is one of the #define constants. You used NO_ANALOGS in your example which configured them all as digital inputs.

Notice in this device you can select AN0 only, AN0 and AN1, AN0 and AN1 and AN2 etc. as analog inputs. You cannot select just AN4 as analog input the the rest as digital. I suspect your device is the same way. So you cannot make RC0 (AN4 in your PIC) analog and the others digital.

There are some excellent posts by Ttelmah on this subject regarding but I can't find the link so maybe he will be kind enough to provide a link to them again.


Last edited by mkuang on Wed Aug 19, 2009 11:50 am; edited 1 time in total
hobby_85



Joined: 17 Aug 2009
Posts: 50

View user's profile Send private message

PostPosted: Wed Aug 19, 2009 11:48 am     Reply with quote

bela wrote:
Personally, I'd just do this:

Code:

boolean mydigi;

mydigi=input(PIN_C0);


to get its digital state.[/code]


yeah, this is what i ended up doing..
Code:
set_tris_c(0b00000001);                         //set rco as input
setup_adc_ports( NO_ANALOGS );                  //set RC0 to digital input

if (PIN_C0 == 1){                              //when button high

blah blah

}

The only reason why im fussing over specifying that it be digital is cause if you didnt in the HI-tech compiler, it wont work. I'm new to CCS, so not sure how it handles here.

thanks mate
hobby_85



Joined: 17 Aug 2009
Posts: 50

View user's profile Send private message

PostPosted: Wed Aug 19, 2009 12:04 pm     Reply with quote

yeah i found some of his posts. thanks alot mkuang and bela.
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