STM32F429 >> Assembly

Button


參考資訊:
1. ds_pdf
2. pm_pdf
3. kit_pdf

Button測試使用B1 USER(PA-0)


GPIO-A Clock


Mode


Pull-up


Input


main.s

  .equiv PORTA_BASE,  0x40020000
  .equiv PORTG_BASE,  0x40021800
  .equiv GPIO_MODER,  0x0000
  .equiv GPIO_PUPDR,  0x000c
  .equiv GPIO_IDR,    0x0010
  .equiv GPIO_ODR,    0x0014
 
  .equiv RCC_BASE,    0x40023800 
  .equiv RCC_AHB1ENR, 0x0030
 
  .thumb
  .cpu cortex-m4
  .syntax unified
 
  .global _start
 
  .text
  .org 0x0000
_start:
  .word 0x20008000
  .word reset
 
  .org 0x0100
  .thumb_func
reset:
  ldr r0, =RCC_BASE
  ldr r1, [r0, #RCC_AHB1ENR]
  orr r1, #(1 << 6) | (1 << 0)
  str r1, [r0, #RCC_AHB1ENR]
 
  ldr r0, =PORTG_BASE
  ldr r1, =(1 << 26)
  str r1, [r0, #GPIO_MODER]
 
  ldr r0, =PORTA_BASE
  ldr r1, [r0, #GPIO_MODER]
  bic r1, #3
  str r1, [r0, #GPIO_MODER]
  ldr r1, [r0, #GPIO_PUPDR]
  bic r1, #3
  orr r1, #2
  str r1, [r0, #GPIO_PUPDR]
 
0:
  ldr r0, =PORTA_BASE
  ldr r1, [r0, #GPIO_IDR]
  lsl r1, #13
  ldr r0, =PORTG_BASE
  str r1, [r0, #GPIO_ODR]
  b 0b
  .end

完成


返回上一頁