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

ADC setup_adc_ports

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







ADC setup_adc_ports
PostPosted: Mon Feb 26, 2007 2:25 am     Reply with quote

Hi,
i'm trying to use 16F877 RA5,
when i use
setup_adc_ports(RA5_ANALOG);
compile it,then output undefined identifier RA5_ANALOG

but when i use setup_adc_ports(RA0_ANALOG);

that is ok

that mean i can only use AN0,not use AN4??? [/code]
shen
Guest







PostPosted: Mon Feb 26, 2007 2:28 am     Reply with quote

the code is
Code:
#include <16F877.H>
#fuses XT, NOWDT, PROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)


void main()
{
     
         
         long int adc_value;
         // The lcd_init() function should always be called once,
         // near the start of your program.
         SET_TRIS_B( 0x0F );
         SET_TRIS_A( 0x00 );
         
         lcd_init();
         
         // Clear the LCD.
         printf(lcd_putc, "\f");
         delay_ms(10);

         setup_adc_ports(RA5_ANALOG);
         setup_adc(ADC_CLOCK_DIV_32);
         set_adc_channel(4);
         
         while(1)
         {
            delay_ms(100);
            adc_value = read_adc();
            printf(lcd_putc,"\f<  V is %lu>",adc_value);
         }//end while(1)
         
         setup_adc(ADC_OFF);

}
Ttelmah
Guest







PostPosted: Mon Feb 26, 2007 4:29 am     Reply with quote

Read the chip's data sheet.
What the compiler supports is limited by what the chip itself can do. The chip does not support having RA5 as an analog pin, unless the pins 'below' this, are also used as analog inputs.
Look in the .h file for the chip, to see the available configuration options. Only three support AN5.

Best Wishes
shen
Guest







PostPosted: Mon Feb 26, 2007 7:32 pm     Reply with quote

16F877.h contain

Code:
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS                           7    // None
#define ALL_ANALOG                           0    // A0 A1 A2 A3 A5 E0 E1 E2
#define AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF 1    // A0 A1 A2 A5 E0 E1 E2 VRefh=A3     
#define AN0_AN1_AN2_AN3_AN4                  2    // A0 A1 A2 A3 A5         
#define AN0_AN1_AN2_AN4_VSS_VREF             3    // 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_AN5_AN6_AN7_VREF_VREF 0x08    // A0 A1 A5 E0 E1 E2 VRefh=A3 VRefl=A2     
#define AN0_AN1_AN2_AN3_AN4_AN5           0x09    // A0 A1 A2 A3 A5 E0       
#define AN0_AN1_AN2_AN4_AN5_VSS_VREF      0x0A    // A0 A1 A2 A5 E0 VRefh=A3           
#define AN0_AN1_AN4_AN5_VREF_VREF         0x0B    // A0 A1 A5 E0 VRefh=A3 VRefl=A2           
#define AN0_AN1_AN4_VREF_VREF             0x0C    // 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 A_ANALOG               0x2         //!old only provided for compatibility 
#define A_ANALOG_RA3_REF       0x3         //!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 ANALOG_NOT_RE1_RE2              0x9   //!old only provided for compatibility 
#define ANALOG_NOT_RE1_RE2_REF_RA3      0xA   //!old only provided for compatibility 
#define ANALOG_NOT_RE1_RE2_REF_RA3_RA2  0xB   //!old only provided for compatibility 
#define A_ANALOG_RA3_RA2_REF            0xC   //!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



can't I use A5 singly ?
Guest








PostPosted: Mon Feb 26, 2007 7:52 pm     Reply with quote

I see the datasheet of 16F877

I know the reason

thanks.

(1) (1) (1)
C
AN6 AN5 AN4 AN3 AN2 AN1 AN0
PCFG3: AN7 HAN/
REF+VREF-
V
(2)
RE2 RE1 RE0 RA5 RA3 RA2 RA1 RA0
PCFG0 Refs
0000 AAAAAAAAVDD VSS 8/0
0001 AAAAVREF+A A A RA3VSS 7/1
0010 DDDA A AAAVDD VSS 5/0
0011 DDDAVREF+A A A RA3VSS 4/1
0100 DDDD ADAAVDD VSS 3/0
0101 DDDDVREF+D A A RA3VSS 2/1
011x DDDD DDDDVDD VSS 0/0
1000 AAAAVREF+VREF-A A RA3RA2 6/2
1001 DDAA A AAAVDD VSS 6/0
1010 DDAAVREF+A A A RA3VSS 5/1
1011 DDAAVREF+VREF-A A RA3RA2 4/2
1100 DDDAVREF+VREF-A A RA3RA2 3/2
1101 DDDDVREF+VREF-A A RA3RA2 2/2
1110 DDDD DDDAVDD VSS 1/0
1111 DDDDVREF+VREF-D A RA3RA2 1/2
A = Analog input D = Digital I/O
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