diff --git a/3-5 GPIO_光敏传感器/Hardware/LED.h b/3-5 GPIO_光敏传感器/Hardware/LED.h new file mode 100644 index 0000000..2d90448 --- /dev/null +++ b/3-5 GPIO_光敏传感器/Hardware/LED.h @@ -0,0 +1,14 @@ +#ifndef __LED_H +#define __LED_H + +enum V_opt{ + high, + low +}; + +void LED_Init(void);//初始化 +void GPIOA_LED(uint16_t GPIO_Pin_x,enum V_opt opt);//点灯 + +void GPIOA_LED_Turn(uint16_t GPIO_Pin_x);//实现翻转电平 + +#endif diff --git a/3-5 GPIO_光敏传感器/Hardware/Lightsensor.c b/3-5 GPIO_光敏传感器/Hardware/Lightsensor.c new file mode 100644 index 0000000..262fef6 --- /dev/null +++ b/3-5 GPIO_光敏传感器/Hardware/Lightsensor.c @@ -0,0 +1,34 @@ +#include "stm32f10x.h" // Device header +#include "stdio.h" + +void LightSensor_Init(void) +{ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); + + GPIO_InitTypeDef GPIO_InitStruct; //初始化GPIO,定义GPIO结构体,以下设置其参数 + GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;//上拉输入模式;GPIO_Mode_Out_OD 开漏模式,低电平驱动,高电平时为高阻态;GPIO_Mode_Out_PP 推挽模式,高低电平都有驱动 + GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13; + GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(GPIOB,&GPIO_InitStruct); + + GPIO_SetBits(GPIOB,GPIO_Pin_13);//初始化LightSensor + +} + + +/*!< Pin x selected ON or OFF + parameter opt is high or low;表示高低电平 +*/ + +enum V_opt{//高低电压 + high, + low +}; + +/* 光敏传感器 返回函数 */ +uint8_t GPIOB_LightSensor_Get(uint16_t GPIO_Pin_x) +{ + return GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_x); +} + + diff --git a/3-5 GPIO_光敏传感器/Hardware/Lightsensor.h b/3-5 GPIO_光敏传感器/Hardware/Lightsensor.h new file mode 100644 index 0000000..bcb1e1a --- /dev/null +++ b/3-5 GPIO_光敏传感器/Hardware/Lightsensor.h @@ -0,0 +1,15 @@ +#ifndef __LIGHTSENSOR_R +#define __LIGHTSENSOR_R + + + +void LightSensor_Init(void); + +/*!< Pin x selected ON or OFF + parameter opt is high or low;表示高低电平 +*/ + +/* 光敏传感器 返回函数 */ +uint8_t GPIOB_LightSensor_Get(uint16_t GPIO_Pin_x); + +#endif