PDA

View Full Version : counting switch events beginner



mrpete
- 22nd April 2009, 13:02
I'm trying to get my pic16f690 to count every time a switch is pressed until it reaches a certain number. I've written a simple test program but it doesn´t work...Somehow the switch is being ignored, the if statement gets executed everytime. switch or no switch. what am i doing wrong?(I´m using the low pin count demo board)
TRISA = %00100000
TRISC.0 = 0
TRISC.1 = 0
led VAR PORTC.0
led2 VAR PORTC.1
butt1 VAR PORTA.5
counter VAR word
bcounter VAR word


counter = 0
bcounter = 0


'************************************************* ****************
loop:

high led2
pause 100
low led2

if butt1 = 0 then
high led
pause 100
low led
counter = counter + 1
endIF
if counter>5 then blink

goto loop
'************************************************* ****************
blink:

bcounter = bcounter + 1
high led
pause 500
low led
PAuse 500
if bcounter<5 then goto blink
counter = 0
goto loop

end

mister_e
- 22nd April 2009, 16:08
Have a look at the following, read all post there, this should give you some hints.
http://www.picbasic.co.uk/forum/showthread.php?t=561

You may also need to debounce your switch once you've discover why it doesn't work.

There's another option, use an internal counter to do the job.