PDA

View Full Version : 16F628 PortA pin connections - wierd



john meiers
- 6th April 2006, 14:01
I can't figure this out - if I pull a PORTA pin low via a 10k and have the program look for a button push (+5v), everything works fine. However, if I try to pull it high with the 10k and have the program look for a button push thats 0v, it will not work. Strangely enough, though, if the pin is hooked directly to 5v (not through a resistor) and a 0v pulse is applied THROUGH a 10k resistor to the pin, it reads it. Is there a way to correct this? I've tried using a PORTA_pullup in the program but evidently you can't do that with this chip?

Melanie
- 6th April 2006, 14:50
PortA works just fine providing you disable the Comparators FIRST!!!! They share PortA and are switched-in by default on Power-up as you discovered when you read the DATASHEET for that PIC.

CMCON=7

Put that somewhere at the top of your code where you initialise the PIC Ports for Input with your TRIS statement (you are using TRISA and TRISB aren't you?) and all will be well.

PortA doesn't have internal pull-up's, an external 10K will be just fine.

Gee, I wish I got $1 for every time disabling Comparators, ADC's and reading the Datasheet came up in conversation...

john meiers
- 6th April 2006, 15:51
Doesn't the ALL_DIGITAL = TRUE command take care of that? I even tried replacing that with CMCON command, but still no worky. With the PORTA.0 pin tied high through the 10k, I still read practically 0v on the pin with the VMM. Here is the code preface:

Device = 16F628A
XTAL = 4

ALL_DIGITAL = TRUE
PORTB_PULLUPS = On
TRISB = 0

Symbol SW1 = PORTA.0
Symbol LED1 = PORTB.0
Symbol LED2 = PORTB.1

Dim CounterA As Byte

TRISA = $F0
PORTB = 0

Any ideas?

Melanie
- 6th April 2006, 15:56
Any ideas?

Yes, you're on the wrong forum. This one is for compilers that work...

But if your pin is showing 0v... it looks like the pin is switched to OUTPUT and not INPUT. TRIS statements take care of that in the MeLabs compilers... but from your code it doesn't look like you've one of those.

Oh... looking again... your TRISA=$F0 has PortA.0 as an OUTPUT.

john meiers
- 6th April 2006, 20:14
ouch..having a bad day? I'm using the Proton IDE Lite compiler...it works great and its free. But fixing that TRIS statement did the trick, so thank you for your help!

Branez
- 10th December 2011, 17:28
......Gee, I wish I got $1 for every time disabling Comparators, ADC's and reading the Datasheet came up in conversation...
I think, you would be a millionaire!
I read a lot in this forum and I find very much smart answers, especially yours.
Thanks!