from machine import Pin
from rp2 import asm_pio, PIO, StateMachine
pin13 = Pin(13, Pin.IN, Pin.PULL_DOWN)
pin14 = Pin(14, Pin.IN, Pin.PULL_DOWN)
pin15 = Pin(15, Pin.IN, Pin.PULL_DOWN)
@asm_pio(out_init = (PIO.OUT_LOW, ) *4, set_init = PIO.OUT_LOW, out_shiftdir = PIO.SHIFT_RIGHT)
def pio_prog():
label("start")
mov(x,0xff) # Init Counter
wrap_target()
label("display")
mov(pins,x) # Output Counter
set(y,16) # Delay
label("dly")
nop()[31]
jmp(y_dec,"dly")
label("readAgain") # Read Button Inputs
in_(null,32)
in_(pins,3)
mov(y,isr)
jmp(not_y,"readAgain") # No Buttons Pressed, Read Again
mov(osr,y)
out(y,1)
jmp(not_y,"dec_x") # Decrement Button Pressed ?
out(y,1)
jmp(not_y,"inc_x") # Increment Button Pressed ?
jmp("readAgain") # If not, Read Again
label("inc_x")
mov(x, invert(x)) # Invert X Register, Twos Compliment
jmp(x_dec, "next") # Decrement X Register
label("next")
mov(x, invert(x)) # Invert X Register, Twos Compliment
jmp("display") # Jump back up to Display
label("dec_x")
jmp(x_dec,"display") # Decrement X Register
jmp("display") # Jump Back Up to Display
wrap()
sm0 = StateMachine(0, pio_prog, freq = 2000, out_base = Pin(0), in_base = pin13)
sm0.active(1)
while True :
sleep(0.1)