Make a LED light up when switch is pushed - assembly language
Wossname
Posts: 174
I'm starting out learning the basics of Propeller Assembly and I'm having some difficulty with testing a pin's input state.
I'm trying to make an LED (pin "P1") light up when I connect P0 to 3.3v and then go off again when P0 is connected to GND.
My code below seems to ignore the high/low state of P0 and simply turns the LED on anyway regardless.
Clearly I'm doing something wrong but I can't seem to figure it out.
I have verified that the loop works by having a separate LED flashing all the time, so I think I'm doing the test wrong in some way.
I'm trying to make an LED (pin "P1") light up when I connect P0 to 3.3v and then go off again when P0 is connected to GND.
My code below seems to ignore the high/low state of P0 and simply turns the LED on anyway regardless.
Clearly I'm doing something wrong but I can't seem to figure it out.
{{ AssemblyToggle.spin }} CON _clkmode = RCFAST PUB Main cognew(@Toggle, 0) DAT org 0 Toggle mov dira, #3 mov Time, cnt add Time, #15 :loop waitcnt Time, Delay xor outa, #1 test 1, ina wz if_z jmp #:off or outa, #2 jmp #:loop :off andn outa, #2 jmp #:loop Delay long 1_000_000 Time res 1
I have verified that the loop works by having a separate LED flashing all the time, so I think I'm doing the test wrong in some way.
Comments
It was the literal 1 in the test operation.
I changed that to be a defined constant ("Switch") and now it works fine.
Ain't it typical? I spend hours trying to figure this out and within 2 minutes of posting on a forum as a last resort I find the answer myself D'oh!
So the most interesting thing is what are you doing DIFFERENT when you write a posting?
I guess if you find out what it is you can do it much earlier and even without writing a posting
best regards
Stefan