PDA

View Full Version : Can't get RA0 to read inputs?!?



kevj
- 17th December 2007, 20:08
I'm pretty sure I've gone over this problem many times now and just can't figure out what's wrong. I can't get a simple input to register a button press.


I've got the button running straight from Vcc to the input with a 10k pull down on the output. I've put a scope probe right on the metal of the input pin itself and it's showing a very clean 5v on that pin when pressing the button so I know the circuit is good. The rest of the funtions (flash LED's) works fine also so I know the PIC is running.

I want the program to do something different when I startup with a button already pressed. Here's what I'm doing to test and no matter what I do, it's just not working.

The device is 16F684




define OSC 20 'Set PBP Osc clock to 20Mhz

CMCON0 = 0 'Turn off comparators, force set to 0 (off)

ANSEL = 0 'Turn off analog input for ports, set digital I/O

TRISA.0 = 1 'RA0 as Input
TRISA.1 = 1 'RA1 as Input
TRISA.2 = 1 'RA2 as Input

TRISC.0 = 1 'RC0 as Input
TRISC.1 = 0 'RC1 as Output
TRISC.2 = 0 'RC2 as Output
TRISC.3 = 0 'RC3 as Output
TRISC.4 = 0 'RC4 as Output
TRISC.5 = 0 'RC5 as Output

bpower VAR PORTA.0 'Power button RA0
boption VAR PORTA.1 'Option button RA1

Startup:
PAUSE 1000
IF PORTA.1=0 THEN
HIGH powerled
ENDIF
IF PORTA.1=1 THEN
HIGH linkled
ENDIF




No matter what I do, the powerled comes on, but Can't ever make the linkled come on (again it does work, later in the code I have it strobe between them and that works fine).

I've tried the above code with PORTA.1, with extra spaces between the = sign, using "bpower" and "boption" instead of the actual port names.

I've got the ANSEL set to 0 so they should be in digital mode. I've gone over all the other registers in the data sheet (noted in the I/O port section) and all of them seem to be where they should be.

Very frustrating. Please help. It's always something dumb that cuases the biggest troubles.

skimask
- 17th December 2007, 20:17
define OSC 20 'Set PBP Osc clock to 20Mhz <----- use DEFINE not define
CMCON0 = 0 'Turn off comparators, force set to 0 (off)


Download and double-check your 16F684 datasheet (DS41202F, Section 8.2, Figure 8-5, Page 58, block in lower right corner).

Common problem, trips me up about every other month on one project or another...

Melanie
- 17th December 2007, 20:19
Well according to my Datasheet CMCON=0 doesn't turn the Comparators OFF and it doesn't do much for setting those pins Digital either! Try a different mode... hint... Page 58 is a good place to look... bah - skimask wins...

mister_e
- 17th December 2007, 20:24
EDIT: AH... everybody at the same time please :D

mister_e
- 17th December 2007, 20:29
define OSC 20 'Set PBP Osc clock to 20Mhz <----- use DEFINE not define

DEFINE is not case sensitive, but the text to it's right edge yes.

kevj
- 17th December 2007, 20:43
Piece of @#$#@!!!


Well that was easy enough. Stupid pic.

I was about 3 cuss words away from going out for cigarettes. I've been spinning my wheels on this problem since early yesterday morning. It seems having a note about this somehwere in the oh...... PORTA section would have been helpful. "Confure them as inputs this way, disable the ananlog ANSEL, yep, and oh by the way.... the comparators are installed to be in your way by default, make sure you set that register also". Blah!!


Okay, thanks guys - and thanks so much for the quick response. I really was at my witts end here. I was starting to wonder if I had a bad batch of PIC's or something, or if I'd managed to zap them somehow.

It's all good.


BTW for anyone else reading this:

CMCON0 = %00000111 'Turn off comparators (CMCON0.0:2 = 111)

is the solution ;)

skimask
- 17th December 2007, 20:46
Piece of @#$#@!!!
Well that was easy enough. Stupid pic.
I was about 3 cuss words away from going out for cigarettes.

If it was me, I'd go out for a smoke break anyways...whether the problem was fixed or not...and keep cussin', regardless...


CMCON0 = %00000111 'Turn off comparators (CMCON0.0:2 = 111)

Keep your eyes on that and the ANSEL as you move thru the various chips. They change a bit here and there.