![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
BLL
Joined: 11 Nov 2006 Posts: 181 Location: Birmingham, UK
|
ADC 16F876A |
Posted: Tue Jun 05, 2007 2:38 pm |
|
|
Hi,
I am trying to configure portA on the 16F876A so that AN0 and AN1 are analogue inputs. AN3 is fed by an external 2.5V reference. I want a voltage out of pin4 which I can vary with the setup_vref function (to vary LCD backlight intensity via suitable buffering). The code I have, which does not work properly but puts out a fixed 1.6V on p4 is:
int dac;
main()
{
setup_adc(ADC_CLOCK_DIV_64);
setup_adc_ports(AN0_AN1_VSS_VREF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
lcd_init(); //lcd on portC
dac = 0;
for(;;)
{
if(dac < 15)
dac++;
else
dac = 0;
//change voltage on pin 4
setup_vref(VREF_LOW | dac);
delay_ms(1000);
}//endfor
}
I have not found the compiler manual very clear at all and am confused!
Can anyone help please?
Thanks
Brian |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Jun 05, 2007 3:08 pm |
|
|
Look at the define VREF_A2. Without this, the Vref is not output.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Jun 05, 2007 4:30 pm |
|
|
Hi Ttelmar,
Obvious when someone explains it!
As a teacher, I get really fed up with how poorly most help guides are put together - the authors just don't seem able to explain things clearly and simply and examples are often too complicated.
Anyway, thanks again.
Brian |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Jun 06, 2007 2:47 am |
|
|
It is a common problem with the CCS stuff, and is made 'worse' by the way that some functions have several different actual 'behaviours' hidden under the skin.
The way to work with the PIC, and CCS, is to use three documents together:
First the PIC data sheet. Though you are working with a 'high level' language, you are dealing directly with the hardware of the chip, and there is no substitute for the data sheet.
Then the .h file for the processor.
Then the compiler manual.
Looking at your problem with these, you can see that to output the Vref voltage, bit 'CVROE' needs to be set (Register 13-1 in the data sheet). This is in the same physical register as the bits to set to select the high range/low range, and the bit to enable the ADC, so presumably would be accessed by the CCS setup_vref function.
Then going to the .h file, looking for the defines used in this function, you find the VREF_A2 define, which accesses the required bit, and though it has no 'comment' explaining what it does, the name itself suggests it's operation.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|