Lined Notebook

[STM32F407VG Discovery] Push Button

by JungWook_

Datasheet의 STM32 pin description versus board functions 부분을 보면 Push Button은 PA0에 연결되어 있습니다.

아래는 Button을 누르면 LED가 점멸하는 코드입니다.

#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>

#define RCCLEDPORT (RCC_GPIOD)
#define LEDPORT (GPIOD)
#define LED_GREEN_PIN (GPIO12)

#define RCCBUTTONPORT (RCC_GPIOA)
#define BUTTONPORT (GPIOA)
#define BUTTONPIN (GPIO0)

static void gpio_setup(void)
{
    /* Enable GPIO clock. */

    rcc_periph_clock_enable(RCCLEDPORT);
    gpio_mode_setup(LEDPORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_GREEN_PIN);

    rcc_periph_clock_enable(RCCBUTTONPORT);
    gpio_mode_setup(BUTTONPORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, BUTTONPIN);
}

int main(void)
{
    gpio_setup();
    /* Blink the LED on the board. */
    while (1) {
        /* Using API function gpio_toggle(): */
        if(gpio_get(BUTTONPORT, BUTTONPIN)){
            gpio_toggle(LEDPORT, LED_GREEN_PIN);    /* LED on/off */
        }
    }

    return 0;
}

```

'Embedded' 카테고리의 다른 글

[STM32F407VG Discovery] External Interrupt  (0) 2021.02.22
[STM32F407VG Discovery] Toggle LED  (0) 2021.02.18
[STM32F407VG Discovery] PlatformIO 사용  (0) 2021.02.18
[Sensor] TFMini Plus on Arduino Leonardo  (0) 2019.11.28
[Verilog] 반가산기  (0) 2018.05.31

블로그의 정보

hongmono

JungWook_

활동하기