When to use ADCON1 in c programming on the pic18f8722

Click For Summary
ADCON1=0x0F is used to configure all pins on PORTA as digital I/O by disabling the analog input mode, which is essential when using pushbuttons and switches. While this setting is often necessary, it may already be configured at reset. Proper functionality also requires correct settings in the TRISA and LATA registers to define which pins are inputs or outputs. It is important to ensure that all three configurations—ADCON1, TRISA, and LATA—are correctly set for the desired operation. Understanding these configurations is crucial for effective programming of the PIC18F8722 microcontroller.
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:

Similar threads

  • · Replies 9 ·
Replies
9
Views
12K
Replies
1
Views
3K
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 24 ·
Replies
24
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 21 ·
Replies
21
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K