微處理器 - STMicroelectronics STM32F103 - Assembly - Button



參考資訊:
https://sourceforge.net/projects/stm32flash/files/

RCC_APB2ENR暫存器,需要開啟GPIO-B、GPIO-C的Clock


LED位置是PC13,設定成Output 50MHz,按鍵則是PB10,設定成Pull-Up


輸出資料


輸入資料


main.s

    .thumb
    .cpu cortex-m3
    .syntax unified

    .equ GPIOB_CRL,   0x40010c00
    .equ GPIOB_CRH,   0x40010c04
    .equ GPIOB_IDR,   0x40010c08
    .equ GPIOB_ODR,   0x40010c0c
    .equ GPIOB_BSRR,  0x40010c10
    .equ GPIOB_BRR,   0x40010c14
    .equ GPIOB_LCKR,  0x40010c18
    .equ GPIOC_CRL,   0x40011000
    .equ GPIOC_CRH,   0x40011004
    .equ GPIOC_IDR,   0x40011008
    .equ GPIOC_ODR,   0x4001100c
    .equ GPIOC_BSRR,  0x40011010
    .equ GPIOC_BRR,   0x40011014
    .equ GPIOC_LCKR,  0x40011018
    .equ RCC_APB2ENR, 0x40021018

    .equ STACKINIT,   0x20005000

    .global _start
    .section .text
    .org 0x0
    .word STACKINIT
    .word _start

    .org 0x100
    .align 2
    .thumb_func
_start:
    ldr r0, =0x00000018
    ldr r1, =RCC_APB2ENR
    str r0, [r1]

    ldr r0, =GPIOB_CRH
    ldr r1, =(2 << 10)
    str r1, [r0]

    ldr r0, =GPIOB_ODR
    ldr r1, =(1 << 10)
    str r1, [r0]

    ldr r0, =GPIOC_CRH
    ldr r1, =(3 << 20)
    str r1, [r0]

loop:
    ldr r0, =GPIOB_IDR
    ldr r1, [r0]
    and r1, 0x400
    lsl r1, 3
    ldr r0, =GPIOC_ODR
    str r1, [r0]
    b loop
    .end

完成