When to use ADCON1 in c programming on the pic18f8722

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 10K views
fractal01
Messages
13
Reaction score
1
Under what circumstances would you use ADCON1=0x0F? All I know at the moment is for using the pushbuttons and using the switches and then I saw a piece of code using the pushbuttons without this line in it and I was wondering whether I was wrong all of this time. I have tried googling and looking in the c18 data booklet but I am having problems with my micro at the moment and can't try writing codes myself. Does anyone know?
 
Physics news on Phys.org
Many years since I programmed the PIC but..

ADCON1 is to do with the A-D converter on PORTA. Looks like setting ADCON1 to 0x0F disables the analog input mode for all pins making Port A digital I/O (even though it's probably already set to that mode on Reset).

http://ww1.microchip.com/downloads/en/devicedoc/39646c.pdf

ADCON1 = — — VCFG1 VCFG0 PCFG3 PCFG2 PCFG1 PCFG0

So 0F means

VCFG<1:0> = 00 => Controls the A-D voltage reference
PCFG<3:0> = 1111 => All pins are Digital I/O

See page 272.

In case it's not obvious.. It's not enough just to write to ADCON1. Port A is configured via the TRISA and LATA registers. All three need to be right on a bit by bit basis if you have some that are inputs, some outputs and some Analog Inputs.
 
Last edited: