Stamp 1 Button Loop Code
microcontrolleruser
Posts: 1,194
in BASIC Stamp
This is from Stamp Editor Help/Language/By Category.
' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL Btn = 0 SYMBOL btnWrk = B2 Main: ' Try changing the Delay value (255) in BUTTON to see the effect of ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat; ' 255 = no auto-repeat (only one action per button press) ' ' The BUTTON instruction will cause the program to branch to ' No_Press unless P0 = 0 PAUSE 5 BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press DEBUG "*" No_Press: GOTO Main
Comments
Doing some prototyping.
Anybody know some improvements we can do to this?
Give us a little time to get it running first.
'something you are actually doing'
This is what we are doing.Thank you.
For one thing it is program design for bigger and better things.
For another it is to test a new board with.A Parallax product if that matters.It should.
'not a reasonable use of the forum's resources.'
If you are an undercover moderator you should make yourself known.
Southern Californian's really, really really do not like attempts to deceive us.
Here's the program in Stamp Editor.
Found some problems with it.
It does not follow the program design we want.
Will think about changing it or scrapping it and using SX.
Surely you wrote this in good humor, but let's clarify for you...
Mike Green is not working undercover. Mike is a very highly regarded member of our community, and he has shared a significant amount of his expertise and time with you here, trying to guide you and answer your questions.
Especially given the amount of time given to helping you, I don't think it unreasonable that Mike asks you to limit your posts to actual questions or your own code and experiments. Rather than posting excerpts from user guides and sometimes posting a running commentary on your thoughts, which understandably takes away from the time available for Mike and others to follow your progress and help with your questions.
(Whilst writing, I should also add that using these forums as a type of personal blogging site is not appropriate, and not allowed according to the forum rules. Perhaps you could read the rules over and see for yourself. I'm sure that refreshing the current rules in your mind could help you become more concise and improve your posting style, whilst also helping you reach a wider audience of contributors to your experiments and discoveries).
http://forums.parallax.com/discussion/134682/forum-rules-and-guidelines#latest
Be careful on how you address forum members that have a steller history with these forums. Mike's observation is correct in the eyes of this Public Moderator.
"What's a Microcontroller?" can be downloaded from Parallax (for free like most of Parallax's educational material). The code examples are written for the BS2, but many are easily modified for the BS1. In particular, look at Chapter 3 Activity #3 starting on page 70. There's a good Wikipedia article on contact bounce if you're interested.
Note: The BUTTON statement shown in one of your earlier posts can also be used to handle a pushbutton, but it's a complicated statement, hard to understand, takes a bit of program memory, and requires the use of a byte variable of which there's a limited amount. It does handle debouncing for you. It's rarely used in "real life".
VonSzarvas
Message received
Publison
Message received
Thank you Mike
The button command 'covers up' the code we are working with.
So Thanks but this will not help us with prototyping flow control with assembler.
See the 5 step flow chart above.
So.Prototyping with Basic Stamp did not work in this case.
Will keep hacking away on using SX assembler.
'good Wikipedia article on contact bounce'
The Googlium tutorial went on for a whole chapter about that. Debounce routines and formulas, programs.
I think our current book side steps that somehow.
Will let you know.
If you seriously would like just to learn about the SX assembler and instruction set, by all means have at it, but keep your postings to the Microcontrollers forum and remember that this is not a blog ... it's a place to ask specific questions about Parallax products. If you have negative comments about what this or that book or posting doesn't say, either ask for help or keep the comments to yourself. If you don't like the answer you get, try to be more specific. Maybe we didn't understand what you wanted.
This is no longer productive.
If it is okay with you I will move on.
Good luck!
Most of the time we just need basic debouncing but no auto repeat with rate. Here's how I do it with the BS1:
You need an input pin (Trigger) and a byte variable (debounce). Adjust the PAUSE and loop count for desired debounce timing; I use 25ms for buttons.
Note that this works because there is no operator precedence in PBASIC 1. This being the case, debounce is either incremented by 5 (input is high) or cleared to zero (input is low).
In point of fact, PBASIC and every other compiled language does that. The LONG DEAD SX/B Compiler (which I helped with while at Parallax) was unique in its approach -- mostly for simplicity, partly for education. Scott Edwards wrote a book about PIC Assembly (I have copy #1) that shows you how to re-create many PBASIC-like instructions in PIC assembly. You can probably find an electronic copy of it somewhere.
By the way... if you switch to the Propeller, you can use PropBASIC which was written by the same guy (Bean) who wrote the SX/B compiler. This will let you see how he translates high-level statements to PASM.
Thanks Jon for all your little gems you bestow one the forums.
Johnny Mac
' Scott Edwards wrote a book about PIC Assembly (I have copy #1) that shows you how to re-create many PBASIC-like instructions in PIC assembly. You can probably find an electronic copy of it somewhere.'
Thank you!
Is it me or are the SX instructions backwards from PIC?
You code MOV W,F and it is executed 'Move contents of File Register to W'?
Got that from a book you may have written.
SX Key guide I think.
I have never written a book on PIC programming.
I just stumbled on this -- it might help you: http://pictutorials.com/index.htm. It has a tutorial on the instruction set.
Thanks Johnny Mac
Bottom line.We've moved up from Basic Stamps to PIC's.
Which is logical because Stamps are based on PIC's.
So.There we have it.
PS: There is no "h" in my name.
Jonny Mac
Thanks!
A good exercise is to write a routine that will reliably toggle an led controlled by a normally open button and still respond to rapid button presses.
The settling time for different buttons varies significantly. Some aviation toggle switches rattle around for ages before they settle down.
Sandy
Let me look at Stamp boards and see which way the pull up resistors go.That's a start.
Parallax writes their program samples for active high.
I do remember an active low routine though.
Might be in 'What's a...'
You're talking about a 'dead man' button.
You have to hold it down to keep it open.
We have just been using regular buttons.