|
|
View previous topic :: View next topic |
Author |
Message |
deltatech
Joined: 22 Apr 2006 Posts: 87
|
undefined identifier error |
Posted: Tue May 02, 2006 7:36 am |
|
|
Hi I have tried to comiple this code i got this from a PIC CCS text book
but i get an error RA0_ANALOG as an undefined identifier . But if use the PIC wizard I get this code
setup_adc_ports(sAN0|VSS_VDD);
and this comiles fine . is this the same code writen differently or should the other code compile ?.
this also works setup_adc_ports(ALL_ANALOG);
but this doesnt setup_adc_ports(RA0_ANALOG);
Code: | #include <16F917.h>
#use delay(clock=4000000)
#fuses HS,NOWDT
#define cutoff 255//128 //2.8 volts
#define neutral_zone 25 //0.5 volts
#use delay(clock=4000000)
void main()
{
int reading;
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
while(TRUE)
{
reading=read_adc();
printf( reading);
// if(reading<(cutoff-neutral_zone/2))
// output_high(PIN_D7);
// else if (reading>(cutoff+neutral_zone/2))
// output_high(PIN_D6);// light_one_led(RLED);
// else
// light_one_led(YLED);
}
}
|
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Tue May 02, 2006 8:07 am |
|
|
Options change from chip to chip and for different versions of the compiler. The available options are normally found in the device header file (in this case the 16F917.H file):
// Constants used in SETUP_ADC_PORTS() are:
#define sAN0 1 //| A0
#define sAN1 2 //| A1
#define sAN2 4 //| A2
#define sAN3 8 //| A3
#define sAN4 16 //| A5
#define NO_ANALOGS 0 // None
#define ALL_ANALOG 31 // A0 A1 A2 A3 A5 |
|
|
Ttelmah Guest
|
|
Posted: Tue May 02, 2006 8:56 am |
|
|
The 'key' difference, is that most (older) chips, only allow a limited number of combinations of analog inputs. On these the 'minimum' setup, with just RA0 as analog, is normally called 'RA0_ANALOG'. However latter chips (of which yours is one), allow individual analog bits to be selected, and on these, instead of having separate defines for all possible combinations, the bits are specified so that they can be 'ored' together.
This also became 'necessary' on some chips which now have so many analog inputs, and configuration options, that several hundred defines would be needed to cover them the 'old way'.
If you require reverse compatibility in this, you could just add:
#define RA0_ANALOG sAN0|VSS_VDD
and then the old definition would be 'emulated'.
As another poster has said, look at the processor's '.h' file to see the definitions for your chip.
Best Wishes |
|
|
|
|
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
|