【发布时间】:2018-09-19 00:05:11
【问题描述】:
我是 stm32f 发现板上的汇编编程新手。我正在尝试在汇编中编写一个可以在 C 中调用的程序(.S 文件)。我希望汇编程序检查是否按下了用户按钮。
我做了一些研究,发现用户按钮位于 GPIOA 端口中,并且可以从 IDR 空间访问它的数据。具体来说,我相信当按下用户按钮时,GPIOA->IDR 的第一位会切换为 1。
这是我写的代码:
.global checkB1
.thumb_func
checkB1:
@; accessing B1
ldr r3,=GPIOA_BASE
ldr r2, [r3,#IDR]
and r0, r2, #GPIO_IDR_IDR_0 @; check if 1 and put in r0
bx lr
我在 C 中调用函数没有问题,但是当按下用户按钮时 r0 永远不会变为 1?
我对自己做错了什么很迷茫,我研究的所有内容都在 C 中完成了整个过程,但它并没有真正帮助我。如果有人知道错误,将不胜感激。
编辑:
我还想包含配置 GPIOA 的初始化代码:
.global initB1
.thumb_func
initB1: @;configure B1 as an input
@; make sure GPIOA is enabled
ldr r3,=RCC_BASE
ldr r2,[r3,#RCC_AHB1ENR]
orr r2,#1 @; set enable bit
str r2,[r3,#RCC_AHB1ENR]
@; configuring B1
ldr r3,=GPIOA_BASE
@; configure B1 as an input
ldr r2,[r3,#MODER]
bic r2,#3 @;clear current value if any of A0 mode
@; new value of A0 mode is general purpose input
str r2,[r3,#MODER] @; ..
@; configure input of B1 as pulldown
ldr r2,[r3,#OPUPDR]
bic r2,#3 @;clear current value if any of control bits
orr r2,#2 @; pulldown mode (bit value: 10)
str r2,[r3,#OPUPDR] @; ..
bx lr
【问题讨论】: