历史上的今天
今天是:2024年08月29日(星期四)
2019年08月29日 | STM32F429 >> 5. 按键控制LED 开关
2019-08-29 来源:eefocus
本工程板级支持包文件适用于野火stm32f429 开发板。
本工程中涉及bsp_led.c, bsp_led.h 等文件,请前往STM32F429 >> 4. 使用固件库点亮LED进行查看
bsp_key.c
/**
******************************************************************************
* @file bsp_key.c
* @author Waao
* @version V1.0.0
* @date 20-Dec-2018
* @brief This file contains some board support package's functions for the KEY.
*
******************************************************************************
* @attention
*
* None
*
******************************************************************************
*/
#include /** * @brief Initialize the key. * @note None * @param None * @retval None */ void KEY_GPIO_Config(void) { GPIO_InitTypeDef GPIO_Structure; RCC_AHB1PeriphClockCmd(KEY1_GPIO_CLK, ENABLE); RCC_AHB1PeriphClockCmd(KEY2_GPIO_CLK, ENABLE); GPIO_Structure.GPIO_Mode = GPIO_Mode_IN; GPIO_Structure.GPIO_Speed = GPIO_Medium_Speed; GPIO_Structure.GPIO_OType = GPIO_OType_PP; GPIO_Structure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Structure.GPIO_Pin = KEY1_PIN; GPIO_Init(KEY1_GPIO_PORT, &GPIO_Structure); GPIO_Structure.GPIO_Pin = KEY2_PIN; GPIO_Init(KEY2_GPIO_PORT, &GPIO_Structure); } /** * @brief Detect the key whether be pressed down actually. * @note None * @param GPIOx: where x can be (A..K) to select the GPIO peripheral. * GPIO_Pin: specifies the port bit to read. This parameter can be GPIO_Pin_x where x can be (0..15). * @retval The status of the input port. */ int Key_Scan(GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin) { if(GPIO_ReadInputDataBit(GPIOx, GPIO_Pin) == KEY_ON) { while(GPIO_ReadInputDataBit(GPIOx, GPIO_Pin) == KEY_ON); return KEY_ON; } else return KEY_OFF; } bsp_key.h /** ****************************************************************************** * @file bsp_key.h * @author Waao * @version V1.0.0 * @date 20-Dec-2018 * @brief This file contains some board support package's definition for the KEY. * ****************************************************************************** * @attention * * None * ****************************************************************************** */ #ifndef __BSP_KEY_H_ #define __BSP_KEY_H_ #include #define KEY1_PIN GPIO_Pin_0 #define KEY1_GPIO_PORT GPIOA #define KEY1_GPIO_CLK RCC_AHB1Periph_GPIOA #define KEY2_PIN GPIO_Pin_13 #define KEY2_GPIO_PORT GPIOC #define KEY2_GPIO_CLK RCC_AHB1Periph_GPIOC #define KEY_ON 1 #define KEY_OFF 0 void KEY_GPIO_Config(void); int Key_Scan(GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin); #endif 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 main.c #include #include #include "bsp_led.h" int main(void) { LED_GPIO_Config(); KEY_GPIO_Config(); LED_BLUE; while(1) { if(Key_Scan(KEY2_GPIO_PORT, KEY2_PIN) == KEY_ON) { LED3_TOGGLE; } if(Key_Scan(KEY1_GPIO_PORT, KEY1_PIN) == KEY_ON) { LED3_TOGGLE; } } }
史海拾趣
|
想做一个cab安装包,安装今日插件,按照网上的说明写了个安装程序setupdll.dll, 但是在模拟器上(pocket pc se 2003 Emulator)安装发现setupdll没有被调用(在函数Install_Exit中加了MessageBox,没有弹出,注册表也没写) cab安装包使用vs2005做的 ...… 查看全部问答> |
|
我想使用EINTT4作按键中断输入.定义如下: UINT32 g_EINTIrq = IRQ_EINT4; UINT32 g_EINTSysIntr = SYSINTR_UNDEFINED; PUBLIC DWORD CPK_Init(DWORD dwContext) { &n ...… 查看全部问答> |
|
dshow CreateMediaType FreeMediaType 无法解析的外部符号 我在wince6.0上做dshow开发,已经包含的头文件和库 #include #include #include #include #include &n ...… 查看全部问答> |
|
我之前安装开发环境的时候,发现PB中Device Driver中的SD选项没有,后来把Updates全装上了,就出现了SD选项。 前几天系统崩溃了,重新装上所有东西后发现就是SD选项没有,各位有没有遇到过这种情况啊????急 … 查看全部问答> |
|
MCS-51单片机中,采用12Mhz时钟,定时器T0采用模式1(16位计数器),请问在下面程序中,p1.0的输出频率 ? MOV TMOD,#01H SETB TR0 LOOP:MOV TH0,#0B1H MOV TL0,#0E0H LOOP1:JNB TF0,LOOP1 CLR TR0 CPL P1.0 SJMP LOOP… 查看全部问答> |




