# 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 –  Matt Ball Oct 23 '11 at 21:13
Check datasheet: ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf page 112 –  GJ. Oct 23 '11 at 21:58
What language/compiler are you using? –  mizo Oct 23 '11 at 22:43

## migrated from stackoverflow.comOct 24 '11 at 2:49

This question came from our site for professional and enthusiast programmers.

See datasheet, Section 11.0 (Register 11-2), page 112.

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.

-