# PIC16F877 analog pin configuration

I've been working with PIC16F877. Can someone please explain how to configure its pins to be analog or digital?

I saw somewhere that we need to configure ADCON1, but don't really understand how that works.

• This sounds like a better question for s.tk/ee Oct 23, 2011 at 21:13
– GJ.
Oct 23, 2011 at 21:58
• What language/compiler are you using? Oct 23, 2011 at 22:43

You select the operation of the pins by setting the four bits PCFG3:PCFG0 in the ADCON1 register according to the table in the datasheet.
The power-on default of these bits is 0000, which means that all the pins AN0...AN7 are configured as analog inputs.
To configure all the AN-pins as digital, you set the PCFG bits to 011x (x means don't care). The rest of the combinations are in the datasheet.