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
Code:
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.
Bookmarks