Upload files to "3-5 GPIO_光敏传感器/Hardware"

This commit is contained in:
2026-02-21 20:02:19 -05:00
parent e4332cafe8
commit 6a3b8de88d
5 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
#include "stm32f10x.h" // Device header
#include "Delay.h"
void KeyInit(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_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
uint8_t Key_GetNum(void)
{
uint8_t Key_Num = 0;
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) == 0)
{
Delay_ms(20);//消抖
while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_1) == 0) ;//按键未弹起,循环等待
Delay_ms(20);
Key_Num = 1;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_11) == 0)
{
Delay_ms(20);//消抖
while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_11) == 0) ;//按键未弹起,循环等待
Delay_ms(20);
Key_Num = 2;
};
return Key_Num;
}