View Full Version : PIC16F676 I/O Problems.
BobEdge
- 4th March 2005, 16:06
Hi,
I am using a PIC16F676 and am having trouble with port A. I am using porta.1 as an input, or rather trying to. It always seems to be read as 0, no matter what state it is in.
The data sheet mentions CMCON register, but I cant find any more information about it.
Anyone know what to do?
Regards
Bob...
Bruce
- 4th March 2005, 17:08
The 676 has analog comparators & A/D which are all configured for analog on power-up.
Place this in the top of your code.
CMCON = 7 ' Turns off comparators
ANSEL = 0 ' Turn off A/D
TRISA.1=1 ' Make RA1 an input
Now you can read the input on RA1.
BobEdge
- 7th March 2005, 13:41
Thanks Bruce, but I need A/D on channel a0, all the other pins are I or O.
Regards
Bob
Bruce
- 7th March 2005, 14:18
ANSEL configures port pins for A/D or digital.
ANSEL = %00000001 ' RA0 = A/D, rest digital I/O.
For ADCON0 & ADCON1 configuration options, see
datasheet A/D section. It's very simple to setup.
BobEdge
- 7th March 2005, 16:37
Thank you Bruce. I have figured it all out now, I think. Wont have time to test it for a day or two. I have:
define OSC 20
define adc_bits 10
define adc_sampleus 50
CMCON = 7 'turns off comparators
ANSEL = 1 'channel 0 analog all others digital
ADCON0 = 129 'right justified, vref = vdd, chan 0 active, A/D converter on
ADCON1 = 96 'fosc/64 (20MHz osc)
Once again thanks for your help.
Regards
Bob...
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.