初始化

This commit is contained in:
2026-05-01 11:13:45 +08:00
commit bb1d10615e
99 changed files with 48378 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
#ifndef __LIGHTSENSOR_H
#define __LIGHTSENSOR_H
#include "stm32f10x.h"
// 光敏电阻引脚定义
#define LIGHT_SENSOR_PIN GPIO_Pin_0
#define LIGHT_SENSOR_PORT GPIOB
#define LIGHT_SENSOR_ADC_CH ADC_Channel_8 // PB0 对应 ADC1 通道8
// 补光灯引脚定义
#define FILL_LIGHT_PIN GPIO_Pin_1
#define FILL_LIGHT_PORT GPIOB
// 补光灯控制宏(根据实际电路调整,假设高电平点亮)
#define FILL_LIGHT_ON() GPIO_SetBits(FILL_LIGHT_PORT, FILL_LIGHT_PIN)
#define FILL_LIGHT_OFF() GPIO_ResetBits(FILL_LIGHT_PORT, FILL_LIGHT_PIN)
// 光线阈值配置(可根据实际环境调整)
#define LIGHT_THRESHOLD_LOW 1500 // 低于此值开灯(光线暗)
#define LIGHT_THRESHOLD_HIGH 2000 // 高于此值关灯(光线亮)
// 使用迟滞区间避免频繁开关
// 函数声明
void LightSensor_Init(void); // 初始化光敏电阻ADC和补光灯GPIO
uint16_t LightSensor_GetValue(void); // 获取光敏电阻ADC值
void LightSensor_Update(void); // 更新补光灯状态(主循环中调用)
uint8_t LightSensor_IsLightOn(void); // 获取补光灯当前状态
#endif