简体   繁体   English

STM32f4上的用户按钮

[英]Userbutton on STM32f4

I am trying to turn on the LEDs when the user button is pressed 我按下用户按钮时试图打开LED

I think I have enabled the peripheral clocks right and the right register. 我想我已经启用了正确的外设时钟和正确的寄存器。 The button is on porta bit 0 该按钮位于porta位0

Here is my code...any help would be great. 这是我的代码......任何帮助都会很棒。 Sorry if it is a bit simple, I am still learning the board. 对不起,如果有点简单,我还在学习董事会。

int main (void)
{
RCC->AHB1ENR=0x9;           
GPIOA->MODER = 0x00000002; 
GPIOD->MODER = 0x55000000;  
GPIOD->OTYPER = 0;          
GPIOD->OSPEEDR = 0;         
GPIOD->PUPDR = 0;           
GPIOA->PUPDR = 0;
GPIOA->OTYPER = 0;
GPIOA->OSPEEDR = 0;

    while(1)
{
    if(GPIOA->IDR == 0x0001){
    GPIOD->ODR = 0xF000;                        
    }
    else{
        GPIOD->ODR = 0;         

        }   
    }   
}

I don't know the STM32f4 but I'm guessing that instead of 我不知道STM32f4,但我猜测而不是

if(GPIOA->IDR == 0x0001)

You want 你要

if ((GPIOA->IDR & 0x0001) != 0)

The original checks that the low bit is on AND all other bits are off while the new version just checks the low bit and ignores the rest. 原始检查低位是否打开以及所有其他位是否关闭,而新版本只检查低位并忽略其余位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM