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

OK to use PortA for analog and digital ?

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



Joined: 01 Jun 2007
Posts: 2

View user's profile Send private message

PostPosted: Fri Jun 01, 2007 9:25 pm     Reply with quote

hi..

i just wanna ask..by the way i'm new to this pic and programming...

if is it ok to used port A if i hv used the port A0 for temperature circuit input...i mean i have analog all port A..

ps: i hope this is not a stupid question~
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Sat Jun 02, 2007 1:05 pm     Reply with quote

Hello,

you can config the ports with the constant defined in the .h file.
for example, here are the constant defined in the PIC18F252.h
Code:
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS                           7    // None
#define ALL_ANALOG                           0    // A0 A1 A2 A3 A5         
#define AN0_AN1_AN2_AN4_VSS_VREF             1    // A0 A1 A2 A5 VRefh=A3             
#define AN0_AN1_AN3                          4    // A0 A1 A3
#define AN0_AN1_VSS_VREF                     5    // A0 A1 VRefh=A3
#define AN0_AN1_AN4_VREF_VREF             0x08    // A0 A1 A5 VRefh=A3 VRefl=A2             
#define AN0_AN1_VREF_VREF                 0x0D    // A0 A1 VRefh=A3 VRefl=A2
#define AN0                               0x0E    // A0
#define AN0_VREF_VREF                     0x0F    // A0 VRefh=A3 VRefl=A2
#define ANALOG_RA3_REF         0x1         //!old only provided for compatibility
#define RA0_RA1_RA3_ANALOG     0x4         //!old only provided for compatibility
#define RA0_RA1_ANALOG_RA3_REF 0x5         //!old only provided for compatibility
#define ANALOG_RA3_RA2_REF              0x8   //!old only provided for compatibility
#define RA0_RA1_ANALOG_RA3_RA2_REF      0xD   //!old only provided for compatibility
#define RA0_ANALOG                      0xE   //!old only provided for compatibility
#define RA0_ANALOG_RA3_RA2_REF          0xF   //!old only provided for compatibility


So, you can write :
Code:
setup_adc_ports(AN0);
for set only A0 as analogue port.

dro
_________________
in médio virtus
dasilvarsa



Joined: 17 May 2007
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 05, 2007 6:07 am     Reply with quote

It is possible to use PortA for Analog as well as digital inputs.
The technique is to configure the port to analog read ther ADC and the configure the port back to digital.

Code:
setup_adc_ports (All_analog);        //start your engines ADC
setup_adc(ADC_CLOCK_INTERNAL );      //
set_adc_channel( 4 );                //
delay_ms(1);

reads=0;
allreads=0;

while (reads < 50){  //tight loop
temp=read_adc();
allreads=temp+allreads;  //sum of reads
++reads;
}  //end while       //end tight loop

setup_adc_ports (no_analogs);     //stop your engines ADC


It is important to do the ADC read code as a function and to do the pin reads or writes as a fuction as well and call the functions in sucession.
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