【Mini-F5265-OB开发板试用测评】按键控制测试
本文介绍了如何使用按键控制 MCU 引脚的输出电平。
原理
由原理图可知
板载用户按键 K1 和 K2 分别与主控的 PB0 和 PB1 相连。
代码
#define _MAIN_C_
#include "platform.h"
#include "gpio_key_input.h"
#include "main.h"
int main(void)
{
PLATFORM_Init();
GPIO_KEY_Input_Sample();
while (1)
{
}
}
函数 GPIO_KEY_Input_Sample()
void GPIO_KEY_Input_Sample(void)
{
static uint8_t KeyState[2] =
{
0, 0,
};
static uint8_t KeyCount[2] =
{
0, 0,
};
printf("\r\nTest %s", __FUNCTION__);
GPIO_Configure();
printf("\r\nPress KEY1 or KEY2...");
while (1)
{
KEY_FSM_Handler(&KeyState[0], &KeyCount[0], GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0), Bit_RESET, "KEY1");
KEY_FSM_Handler(&KeyState[1], &KeyCount[1], GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1), Bit_RESET, "KEY2");
PLATFORM_LED_Enable(LED1, (FunctionalState)GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0));
PLATFORM_LED_Enable(LED2, (FunctionalState)GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1));
PLATFORM_DelayMS(10);
}
}
效果
按键控制 LED
总结
本文展示了板载按键控制 LED 的项目实现。