PDA

View Full Version : Solved Why the difference between these two button reading programs in PASM and SPIN



Tony B.
03-26-2012, 01:30 PM
I am working on a Propeller Professional Development Board using button Zero and LED 9. Both programs work as coded, but with this one puzzling result. When I run the PASM code and while it is waiting for the a button press the LED is dimly lit. When you press and hold the button the LED is brightly lit as you would expect. Release the button and the LED returns to the dimly lit state. The SPIN code works as well, but the LED is off until the button is pressed and held. I'm returning to working with PASM because I am beginning a project which needs it. I was reviewing some learning/practice code I had worked with for some time and rediscovered this old problem I never got figured out.



CON
_clkmode = xtal1 + pll16x ' Enable External Crystal and PLL X 16
_xinfreq = 5_000_000 ' External Crystal Frequency 5Mhz
PUB Main
{Launch cog to run Propeller Assembly code}
cognew(@entry, 0) 'Launch new cog

DAT
org 0 'Begin at Cog RAM address 0

entry mov dira, LED 'Set pin 9 to output
loop waitpeq Button, Button 'Wait till button is pressed
xor outa, LED 'Turn on LED
waitpne Button, Nobutton 'Wait till button is released
xor outa, LED 'Turn off LED
jmp #loop 'Loop


LED long |< 9
Button long 0
Nobutton long |< 0




CON
_clkmode = xtal1 + pll16x ' Enabled External Crystal and PLL X16
_xinfreq = 5_000_000 ' External Crystal Frequency
VAR

OBJ

PUB Main
dira[9] := 1
repeat
waitpeq(%0, %1, 0)

outa[9] := 1

waitpne(%0, %1, 0)

outa[9] := 0


Thanks,
Tony

kuroneko
03-26-2012, 01:35 PM
Your PASM waitpeq uses 0 as a mask and target which makes it effectively a 6 cycle nop. If you want to wait use non-zero masks, e.g.

waitpeq mask, mask ' wait for pin high
waitpne mask, mask ' wait for pin low

mask long |< pin

Tony B.
03-26-2012, 01:46 PM
Thanks Kuroneko. Problem solved.