Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
2  
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.com Oct 24 '11 at 2:49

2 Answers

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.

share|improve this answer

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.

share|improve this answer
1  
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. – Olin Lathrop Oct 24 '11 at 12:41
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. – AndreKR Oct 24 '11 at 13:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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