PDA

View Full Version : 16F876 ADCON,CMcon,Tris settings



RFsolution
- 10th March 2010, 17:22
Hi

This is the first time I will use a 16F876 asfar as i can read in the forum, some confusion on the port configuration:

I need to have:
RA0-RA3,RA5(AN4) analog in (10bit ADC), RA4 digital out,
RB0-RB3 + RB6,7 digital out,RB4,5 digital input,
RC0-RC5 digital out,RC6+7 TX+RXD usart

I think i have to set:

ADCON1= %00000010 ' sets RA4 to digital,RA0-3,RA5 analog in, (Bit 7 ? Left or right justified ?)
Trisa %00101111
Trisb %00110000
Trisc %10000000

ADCON0= ?
CMCON= ?
how do I set 10bit ADC ?

Bruce
- 10th March 2010, 17:46
Looks good. Write ADCON1= %10000010 for 10-bit.

Note: The 16F876 does not have comparators. The A version does.

RFsolution
- 10th March 2010, 18:14
Thanks Bruce

What if I use the 16F876a version ?

Bruce
- 10th March 2010, 18:20
The A version has comparators so then you would use CMCON = 7. Even though it defaults to this value at POR, it's good to include this so you remember. Some PIC types with comparators don't default to disabled.

A/D looks pretty much the same.

Melanie
- 10th March 2010, 18:46
As well as implicitly disabling the COMPARATORS, I also disable the VOLTAGE REFERENCE MODULE on the 16F877A...

CMCON=7
CVRCON=0

Those two lines are the ONLY differences between the 'A' and the non-A I've ever included.

You can then progress up to the 18F242/252 (with minor ADC software changes), but there's a HARDWARE difference with the ADC's once you go up to the 18F2420/18F2520 series (eg ADCON1 ADC Configuration %xxxx0100 from the 16F876 can't be pin configured on the 18F2420's).

Bruce
- 10th March 2010, 18:55
Good catch Melanie.

RFsolution
- 10th March 2010, 19:26
Thanks,

What about ADCON0 ?

do I have to set the clock for the ADC ?

Bruce
- 10th March 2010, 20:32
It really would help folks, help you, if you included a tad more information.

If you're using ADCIN, then it normally handles ADCON0 for you. If you plan on doing it all
manually, then for sure you need to setup everything yourself. Including ADCON0.