When to use ADCON1 in c programming on the pic18f8722

In summary, ADCON1=0x0F is used to disable the analog input mode for all pins on PORTA and make them digital I/O. This information can be found on page 272 of the c18 data booklet and it is important to also configure the TRISA and LATA registers correctly for the desired input/output settings.
  • #1
fractal01
14
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
  • #2
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:

FAQ: When to use ADCON1 in c programming on the pic18f8722

When should I use ADCON1 in c programming on the pic18f8722?

The ADCON1 register is primarily used for configuring the analog-to-digital converter (ADC) in the PIC18F8722 microcontroller. It should be used whenever you need to take analog voltage readings from external sensors or other devices.

How do I use ADCON1 in my c program?

To use ADCON1 in your c program, you will need to first initialize the register with the appropriate settings for your application. This can be done by setting the bits in the ADCON1 register using bitwise operators. Once initialized, you can then use the ADC module in your program to read analog voltage values.

What are the most important bits in ADCON1 for ADC configuration?

The most important bits in ADCON1 for ADC configuration are the ADCS2-ADCS0 bits, which determine the conversion clock source, and the PCFG3-PCFG0 bits, which select the analog input pins to be used. These bits should be carefully set to ensure accurate and efficient ADC operation.

Can I change the ADCON1 settings during program execution?

Yes, you can change the ADCON1 settings during program execution if necessary. However, it is recommended to only change these settings during the initialization phase of your program to avoid any potential errors or interruptions in the ADC operation.

Is ADCON1 necessary for all ADC operations on the PIC18F8722?

No, ADCON1 is not necessary for all ADC operations on the PIC18F8722. It is only required if you need to configure the ADC module for specific settings or if you want to select the input channels for the ADC. If you do not need to change these settings, you can simply use the default settings and skip using ADCON1 in your program.

Similar threads

Back
Top