按键控制 技术点
- 控制LED的 GPIO 设置为输出
- 控制按键的GPIO 设置为上拉输入
按键部分代码
Key.c
#include "stm32f10x.h"
#include "Delay.h"
void Key_Init(void){
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode= GPIO_Mode_IPU; //ÉÏÀÊäÈë
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz ;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
uint8_t Key_GetNum(void)
{
uint8_t KeyNum = 0;
if( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) ==0 ){
Delay_ms(20);
while( GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) ==0 );
Delay_ms(20);
KeyNum = 1

博客围绕STM32单片机展开,介绍了按键控制和光敏传感两部分内容。按键控制涉及LED和按键的GPIO设置,给出了按键、Led部分代码;光敏传感部分将传感器设为上拉输入,实现无光亮、有光暗的效果,也给出了相关代码。
最低0.47元/天 解锁文章
2524

被折叠的 条评论
为什么被折叠?



