from machine import Pin
import array as arr
import time
boton_incremento = Pin(18, Pin.IN, Pin.PULL_DOWN)
boton_decremento = Pin(19, Pin.IN, Pin.PULL_DOWN)
registros = arr.array('i', [
0x40014000, # IO_BANK0_BASE
0xd0000000 # SIO_BASE
])
@micropython.asm_thumb
def contador_binario(r0):
# Configuración de SIO
ldr(r1, [r0, 0])
mov(r2, 5) # Function 5, SIO for GPIO0
str(r2, [r1, 0x004]) # GPIO0_CTRL
str(r2, [r1, 0x00c]) # GPIO1_CTRL
str(r2, [r1, 0x014]) # GPIO2_CTRL
str(r2, [r1, 0x01c]) # GPIO3_CTRL
# Habilitación de OE
ldr(r1, [r0, 4]) # dirección base de SIO
mov(r2, 15) # carga 1 para GPIO0, GPIO1, GPIO2 y GPIO3
str(r2, [r1, 0x24]) # 0x24 GPIO output enable (GPIO_SET_OE)
# Ciclo infinito
label(eti1)
mov(r3, 0) # Conta = 0
label(eti2)
ldr(r1, [r0, 4])
str(r3, [r1, 0x10]) # GPIO_OUT <- R3
label(eti3)
bl(delay)
# Código para el boton incremento
ldr(r1, [r0, 4]) # dirección base de SIO
ldr(r2, [r1, 0x04]) # Lee GPIO_IN
mov(r1, 1) # r1 = 0x01
lsl(r1, r1, 18) # Máscara para el boton
and_(r2, r1) # Solo conserva al boton
# Código para el boton decremento
ldr(r1, [r0, 4]) # dirección base de SIO
ldr(r4, [r1, 0x04]) # Lee GPIO_IN
mov(r1, 1) # r1 = 0x01
lsl(r1, r1, 19) # Máscara para el boton
and_(r4, r1) # Solo conserva al boton
#Si presionado incremento
cmp(r2, 0)
beq(eti4)
add(r3, 1)
cmp(r3, 10)
beq(eti1)
b(eti2)
#Si presionado decremento
label(eti4)
cmp(r4, 0)
beq(eti3)
sub(r3, 1)
mov(r6, 1)
neg(r6, r6)
cmp(r3, r6)
bgt(eti2)
mov(r3, 9)
b(eti2)
label(delay)
mov(r1, 1)
lsl(r1, r1, 25) # Número muy grande
label(loop2)
sub (r1, 1) # resta 1 del registror0
bne(loop2)
bx(lr)
contador_binario(registros) # Contador de 0 a 3