PDA

View Full Version : 12f629 push button & LED



yankee
- 9th February 2006, 14:45
OK, I'm stumped. I know I missed something stupid here and I need some insight.

I have an N.O. switch on gpio5 with a pullup resistor which is supposed to toggle an LED on gpio0. Nothing happens, however when I configure the code for a 16f628a, it works fine. I also checked the IC by loading a simple blink program and that works fine.

Oscillator is set to INTOSC
Watchdog enabled
Power-up enabled
MCLR as input
Brownout disabled

Here's the code:

cmcon = 7

trisio.5 = 1 ' port5 is an input

led1_status var bit
button1 var gpio.5
led1 var gpio.0

main:
sleep 1 ' sleep for about 1 second
if button1 = 0 then ' if the button is pressed

if led1_status = 1 then ' if its last state was 1

led1_status = 0 ' make it 0
low led1
pause 500 'debounce

else

led1_status = 1 ' the last state was a 0 so now make it a 1
high led1
pause 500 'debounce

endif

endif

milestag
- 9th February 2006, 21:11
Looks like it executes your code once, then it's done. There is no LOOP.

Try putting a GOTO MAIN at the end of your program. That way it keeps checking the button.

yankee
- 9th February 2006, 21:41
I know I'm new at this, but I still can't believe that I missed that one. It works!

Now, any idea why it would work on the 16f628a without the goto main and not on the 12f629?

Many Thanks

trying
- 10th February 2006, 01:45
"edit " I spoke with out thinking sorry