Begineer Problem
Hi ! iam begineer in microcontroller. iam using BS2sx for controlling my final year project.
i want my output5 high when input1 on and off for·5 times. please someone check my program. its not working.counter is not·accurate.
INPUT 1
OUTPUT 5
cnt VAR Byte
cnt = 0
MAIN :
····· IF IN1=1 THEN ADD
····· GOTO MAIN
ADD:
····· PAUSE 1000
····· cnt = cnt +·5
····· IF cnt <·5 THEN MAIN
····· HIGH 5
····· DEBUG " OK "
····· GOTO MAIN
regards
aklaken.
i want my output5 high when input1 on and off for·5 times. please someone check my program. its not working.counter is not·accurate.
INPUT 1
OUTPUT 5
cnt VAR Byte
cnt = 0
MAIN :
····· IF IN1=1 THEN ADD
····· GOTO MAIN
ADD:
····· PAUSE 1000
····· cnt = cnt +·5
····· IF cnt <·5 THEN MAIN
····· HIGH 5
····· DEBUG " OK "
····· GOTO MAIN
regards
aklaken.

Comments
I'm a bit surprised it's not more intuitive that if you want to increment a counter by one, you add one to it, not 2, 5 or anything else:
cnt = cnt + 1 'Increment the counter by one
Regards,
Bruce Bates
thanks again
regards
aklaken·
Dave
You say in your program than you want to "press and release" the button; the code below shows how (one method, there are many) to do that.
' {$STAMP BS2sx} ' {$PBASIC 2.5} Btn PIN 1 Alarm PIN 5 btnCount VAR Nib Reset: btnCount = 0 LOW Alarm ' make output and off Main: DO WHILE (btnCount < 5) ' monitor until count = 5 DO : LOOP WHILE (Btn = 0) ' wait for press PAUSE 100 ' debounce delay DO : LOOP UNTIL (Btn = 0) ' force release btnCount = btnCount + 1 ' update count LOOP HIGH Alarm ' turn on DEBUG "Alarm", CR PAUSE 2000 ' delay for alarm output GOTO Reset ' start over▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA