【东软载波ESF0654 PDS开发板活动】+按键

2020-03-12 19:44发布

今晚捣鼓了一下按键。
代码:
#define LED2_GPIO_PORT GPIOC
#define LED2_GPIO_PIN  MD_GPIO_PIN_9       

#define KEY_GPIO_PORT GPIOF
#define KEY_GPIO_PIN  MD_GPIO_PIN_0       


#include "main.h"

/** @addtogroup Projects_Examples_MD
  * @{
  */

/** @addtogroup Examples
  * @{
  */
#define uchar unsigned char
#define uint  unsigned int
       

/**
  * @brief  This function configures GPIO
  * @param  None
  * @retval None
  */
void config_gpio(void)
{
        md_gpio_set_pin_function(KEY_GPIO_PORT, KEY_GPIO_PIN, GPIO_FUNC_1);
        md_gpio_set_pin_push_pull(KEY_GPIO_PORT, KEY_GPIO_PIN);
        md_gpio_set_pin_mode_input(KEY_GPIO_PORT, KEY_GPIO_PIN);
       
       
       
        md_gpio_set_pin_function(LED2_GPIO_PORT, LED2_GPIO_PIN, GPIO_FUNC_1);
        md_gpio_set_pin_push_pull(LED2_GPIO_PORT, LED2_GPIO_PIN);
        md_gpio_set_pin_mode_output(LED2_GPIO_PORT, LED2_GPIO_PIN);
}

/**
  * @brief  Test main function
  * @retval Status.
  */
int main()
{
        md_init_1ms_tick();
        config_gpio();
       
        while (1)
        {
                if(md_gpio_get_input_data(KEY_GPIO_PORT, KEY_GPIO_PIN)==0)
                {
                        md_gpio_set_pin_low(LED2_GPIO_PORT, LED2_GPIO_PIN);
                }
                else
                {
                        md_gpio_set_pin_high(LED2_GPIO_PORT, LED2_GPIO_PIN);
                }
        }
}

效果图:


1条回答
一路向北lm
1楼 · 2020-03-12 23:34.采纳回答
你们好狡猾,都用 ST-Link

一周热门 更多>