Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.2 kB
1
Indexable
Never
@ Assembler program to flash the built-in LED on the Raspberry Pi Pico W
@ The flash cycle is one second long (500ms on, 500ms off)

.EQU LED_BUILTIN, 0     @ GPIO number for built-in LED on Pico W
.EQU GPIO_OUT, 1        @ GPIO output mode
.EQU sleep_time, 500    @ Sleep time in milliseconds (500ms)

.thumb_func             @ Necessary because SDK uses BLX
.global main            @ Provide program starting address to linker

main:
    MOV R0, #LED_BUILTIN  @ Load LED pin number
    BL gpio_init          @ Initialize GPIO pin

    MOV R0, #LED_BUILTIN  @ Load LED pin number
    MOV R1, #GPIO_OUT     @ Set pin as output
    BL link_gpio_set_dir  @ Set GPIO direction

loop:
    MOV R0, #LED_BUILTIN  @ Load LED pin number
    MOV R1, #1            @ Turn LED on
    BL link_gpio_put      @ Apply GPIO output

    LDR R0, =sleep_time   @ Load sleep time
    BL sleep_ms           @ Sleep (LED on)

    MOV R0, #LED_BUILTIN  @ Load LED pin number
    MOV R1, #0            @ Turn LED off
    BL link_gpio_put      @ Apply GPIO output

    LDR R0, =sleep_time   @ Load sleep time
    BL sleep_ms           @ Sleep (LED off)

    B loop                @ Repeat indefinitely
Leave a Comment