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.
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI'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.
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.
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.