Input and output in PASM
Alexander (Sandy) Hapgood
Posts: 360
I've been trying to learn assembly and was trying to figure out how to set the output of a pin based on the input of another pin. The output part came fairly easily but it took a while to figure out the input part. The following is the code I finally put together.
This code and setup is guaranteed to work at my house on my PPDB.
This code and setup is guaranteed to work at my house on my PPDB.
{{ Operate an LED based on switch position Demonstrates input and output in assembly 392 +3.3─────┳─────┐ │ ┫SW1 100k │ │ pin 2────┘  470 pin 3────────┐ │  }} con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 var pub Main 'Launch assembly code into cog 1 coginit(1, @switch, 0) dat org 0 switch mov mask1, #1 shl mask1, #2 andn outa, mask1 'make pin 2 an input mov mask2, #1 shl mask2, #3 or dira, mask2 'make pin 3 an output or outa, mask2 :start test mask1, ina wc 'set carry flag if bit set if_c andn outa, mask2 'button up - LED off if_nc or outa, mask2 'button down - LED on jmp #:start mask1 res 1 mask2 res 1
Comments
Check out the muxc and muxnc instructions. They can be used to set/clear bits of outa based the state of the carry flag with one instruction instead of two conditional instructions.
-Phil