PDA

View Full Version : Question Regarding Port A on 16F876A



jevert
- 26th February 2009, 12:53
I am utilizing all of the I/O Pins on a 16F876A. I would like to configure port A with 3 analog pins (AN0-AN2) and utilize RA3-RA5 as general purpose IO pins.

Based on the data sheet and its reference to configuring the ADCON1 register it does not look like this is possible. I am wondering what happens if I configure the entire port as an analog port then simply convert RA3-RA5 as outputs? For Example:

ADCON1 = 2 ' CONFIGURE PORT A TO ANALOG (010)
TRISA.3 = 1 ' CONFIGURE PIN AS INPUT
TRISA.4 = 0 ' CONFIGURE PIN AS OUTPUT
TRISA.5 = 0

If I read or write to RA3-RA5 as analog inputs or outputs what affect does this have on AN0-AN2?

Any input appreciated.

Best regards,
Joe.

aratti
- 26th February 2009, 13:28
If I read or write to RA3-RA5 as analog inputs or outputs what affect does this have on AN0-AN2?

Surely you ment digital, the answer is none.

Suggest to use portA.3 as an output and portA.4 as an input since A4 is an open-drain type

Alberto

mister_e
- 26th February 2009, 13:45
If you write to an analog pin, set as an output, results will differ from time to time, so Just don't do that ;)

Better practice is to modify your hardware assignment to what your PIC can do, and/or choose another PIC which have more flexibility about analog pin configuration.

jevert
- 26th February 2009, 14:00
Surely you ment digital, the answer is none.

Suggest to use portA.3 as an output and portA.4 as an input since A4 is an open-drain type

Alberto

Thank you for writing what I was thinking! Yes you are correct. I guess I am confused about the configuration of ADCON1 register, particularly bits 0-3. It appears this configures the port as whole and this determines which pins can/will be analog inputs or digital IO pins. In particular I read this post which concerns me:

http://www.picbasic.co.uk/forum/showthread.php?t=10438&highlight=ANALOG

Since the PCB is already developed it concerns me that the I/O pins can only be configured per the chart in the datasheet. So, if this is configured so that all pins are analog then specific pins are converted after that to digital I/Os what impact does this have. If these pins can be individually configured why is the ADCON1 register even needed?

Thanks,

Joe