PDA

View Full Version : Begineer Problem

akla
02-15-2005, 01:02 PM
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 :
····· GOTO MAIN
····· PAUSE 1000
····· cnt = cnt +·5
····· IF cnt <·5 THEN MAIN
····· HIGH 5
····· DEBUG " OK "
····· GOTO MAIN

regards
aklaken.

Bruce Bates
02-15-2005, 01:09 PM
aklaken -

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

akla
02-15-2005, 01:39 PM
thanks bruce, i not reliase it, now its working
thanks again
regards
aklaken·

achilles03
02-15-2005, 10:04 PM
Also, is the input on pin 1 transitioning from high to low no faster than once a second? If not, that "pause 1000" statement might need fine tuning.

Dave

Jon Williams
02-15-2005, 11:10 PM
Give this a try.· It's a little more verbose than your code -- you'll find as programs grow this style is easier to read and maintain.·

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