2
\$\begingroup\$

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.

\$\endgroup\$
3

2 Answers 2

2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

If you are just using the pins for output, they don't have to be configured as digital. That is only required for digital inputs. It's implied by all the data sheets, but a lot of people don't realise it. It is mentioned in the data sheets for the latest parts.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I'm not so sure this is really true for all parts, especially older ones like the 16F877. I seem to remember running into this problem long ago wondering why my pin wasn't wiggling and not realizing that analog functions had to be disabled. I have seen what you are talking about in newer datasheets, but that doesn't mean it applies to older parts. \$\endgroup\$ Oct 24, 2011 at 12:41
  • \$\begingroup\$ From the A/D conversion chapter of the datasheet: If the TRIS bit is cleared (output), the digital output level (V_OH or V_OL) will be converted. \$\endgroup\$
    – AndreKR
    Oct 24, 2011 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.