import array as arr
# Código con cuatro salidas GPIO
regdata = arr.array('i', [
0x40014000, # Dirección base de IO_BANK0 (página 243)
0xd0000000 # Dirección base de SIO (página 42)
])
@micropython.asm_thumb
def blink(r0):
# Configuramos los LEDs
ldr(r1, [r0, 0])
mov(r2, 5) # Función 5, selecciona SIO para GPIO0
str(r2, [r1, 0x04]) # GPIO0_CTRL
str(r2, [r1, 0x0C]) # GPIO1_CTRL
str(r2, [r1, 0x14]) # GPIO2_CTRL
str(r2, [r1, 0x1C]) # GPIO3_CTRL
ldr(r1, [r0, 4]) # Dirección base de SIO
mov(r2, 15) # Carga 1 para GPIO0, GPIO1, GPIO2, GPIO3
str(r2, [r1, 0x24]) # 0x24 GPIO output enable
mov(r3, 0)
label(ciclo)
# LED encendido
ldr(r1, [r0, 4]) # Dirección base de SIO
str(r3, [r1, 0x10])
add(r3, 1)
mov(r2, 0x0F) # GPIO0, GPIO1, GPIO2, GPIO3 encendidos
and_(r3, r2)
# Verificamos que no se exceda el 9
mov(r2, 10) # Ponemos 10 porque debe llegar al 9
cmp(r3, r2)
bne(continua)
mov(r3, 0) # Reiniciamos si es = 10
label(continua)
bl(delay)
b(ciclo)
label(delay)
mov(r2, 1)
lsl(r2, r2, 24) # Número muy grande
label(loop)
sub(r2, 1) # Resta 1 del registro r2
bne(loop)
bx(lr)
blink(regdata)