push switch input
kingneb
Posts: 65
How do you read the status of a push switch on ra.0·and index a count variable when it goes high.· I want to decrement the count variable when·a push switch is on ra.1·is pushed.· I also want the microcontroller to ignore the push switches that are held down (only recognizes a seemingly·instantanious push).· Actually the push switch equivilents·are bits on the pc's parallel port.· That is why the "held down" thing is critical.· If that bit remains hi, the byte variable with increase to 255 at the rate of gazillion times, lol.· i would like·SX/B code please.
Thanks·
Post Edited (kingneb) : 10/12/2005 2:45:19 AM GMT
Thanks·
Post Edited (kingneb) : 10/12/2005 2:45:19 AM GMT
Comments
Main:
· IF RA.0 = 1 THEN
····INC count
··· DO
····· WAIT_MS 25
··· LOOP UNTIL RA.0 = 0
· ENDIF
· IF RA.1 = 1 THEN
····DEC count
··· DO
····· WAIT_MS 25
··· LOOP UNTIL RA.1 = 0
· ENDIF
I put a 25 ms debounce delay in to prevent very fast bounce from causing false triggering.· WAIT_MS is the label to a subroutine that holds the PAUSE instruction (so that PAUSE is only compiled once).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
http://www.parallax.com/sx/downloads.asp
Still, you don't need the simulator running to see that you've got a tremendous number of errors.· SX/B may be easy to use, but it has to be treated as seriously as assembly language.· Sloppy programming habits tolerated by other versions of BASIC will bite you in SX/B.
Obvious problems:
· - "count" is an SX/B keyword (so it can't be used as a variable name)
· - "hi" and "lo" are not keywords
· - "wait_ms" is not defined or coded
· - "wait_us" is not a keyword, and not defined and coded as a subroutine
· - You have math that would exceed eight bits
I think you get my point.· You didn't spell it out, but you seem to want to PWM the RB.0 port based on the value of the counter.· I've attached a program that does what I think you want it to do.· It compiles and runs in the simulator just fine (I'm in a hotel right now, so I have no hardware to actually run the program on).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Does __PARAM1 and 2 mean the first and second parameter?
Does WAIT_US SUB 1, 2 mean declare a sub routine that works with two parameters?
1. __PARAMCNT is set to the number of parameters you pass to a subroutine; this can be used by the subroutine as I did in the delay routines
2. Yes, __PARAM1..__PARAM4 are variables that carry your parameters, and are also used as working variables for keywords like PAUSE, etc.
3. When subroutines that take parameters are delcared, you can specifiy a minum and maximum number of parameters allowed -- this helps the compiler flag self-created syntax errors.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax