INPUT: How To
I'm new to the SX and I'm having trouble getting info into the SX.
I have the Professional Development board and have plugged a wire from one of the push buttons into RA.0. It is my understanding that the push button has a pull up resistor and goes low when pressed.
Here is my code:
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
ID············· "SXB 1.50"
PROGRAM Start
Start:
· input RA.0
Main:
· watch RA.0
GOTO Main
When I click the debug button, the Watch window shows RA.0 as 0 (zero) regardless of whether or not a push the button.
I've tried other pins and other buttons, but I can't ever get the input pin to read 1. Am I using the INPUT function improperly? Or perhaps I am using the Watch function wrong? Please help [noparse]:)[/noparse]
I have the Professional Development board and have plugged a wire from one of the push buttons into RA.0. It is my understanding that the push button has a pull up resistor and goes low when pressed.
Here is my code:
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
ID············· "SXB 1.50"
PROGRAM Start
Start:
· input RA.0
Main:
· watch RA.0
GOTO Main
When I click the debug button, the Watch window shows RA.0 as 0 (zero) regardless of whether or not a push the button.
I've tried other pins and other buttons, but I can't ever get the input pin to read 1. Am I using the INPUT function improperly? Or perhaps I am using the Watch function wrong? Please help [noparse]:)[/noparse]
Comments
\ WATCH RA.0, 1, ubin
\ BREAK
Start the program in Debug mode, then select Poll; the watch window should change to indicate any changes on RA.0. BTW, all pins default to input, so you don't even need that INPUT line in your program. Do it like this:
Post Edited (JonnyMac) : 4/17/2007 5:24:38 AM GMT
Can you confirm that you are using an SX-Key as the programmer and not an SX-Blitz which does not support debugging?
Also, it has been my experience that I can not "Poll" (the button is disabled) when there is a BREAK command within the program.
Finally, I have had some trouble before trying to WATCH a single bit. In some cases it worked but in other cases it did not work. RA.0 has been reported to work whereas RA.1 reportedly does not. See WATCHing a pin with SX/B (Without using a variable) and SX/B - Watched Bit not Showing Changes for more details.
- Sparks
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"
Benjamin Franklin
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
There are at least two choices when using Watch and Break statements along with the [noparse][[/noparse]Poll] button.
If you include a Break statement within your program you can only have data "polled" from the program at that location. It happens automatically whenever the Break statement is encountered. This is probably preferred for the use described in this thread.
If you do not include a Break statement you can then press the [noparse][[/noparse]Poll] button (enabled once the program is running) at any time to capture a snapshot of what the SX was seeing and doing at that particular moment.
So with a Break statement you can poll automatically but only from one program location whereas without a Break statement you can poll data from any part of the program but only when you press the button.
I hope this clarifies what I may have made confusing.
- Sparks
Consider this code:
output rb.0
input ra.0
Start:
if ra.0 = 0 then
rb.0 = 1
else
rb.0 = 0
endif
GOTO Start
Compared to this code:
output rb.0
input ra.0
Start:
if ra.0 = 0 then
HIGH rb.0
else
LOW rb.0
endif
GOTO Start
When I hook an LED up to RB.0 and press the button on ra.0, the led blinks as expected with the bottom code... but nothing happens at all when I press the button using the top code. Is this what you guys would expect? Thanx for your continued support. I'll figure this thing out sooner or later [noparse];)[/noparse]
Any code before "Start:" will never get executed. So your "OUTPUT RB.0" and "INPUT RB.0" never get executed.
HIGH and LOW will force the pin to be an output. "RB.0 = 1" and "RB.0 = 0" do not, they simply set the output latch. So if the pin is an input, you won't see anything on your led.
The best way to handle this is to DEFINE the pin as an output. As in:
LEDS PIN RB.0 OUTPUT
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"
Benjamin Franklin
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·