- #include "lsens.h"
- #include "delay.h"
- //////////////////////////////////////////////////////////////////////////////////
- //本程序只供學習使用,未經作者許可,不得用于其它任何用途
- //ALIENTEK戰(zhàn)艦STM32開發(fā)板V3
- //LSENS(光敏傳感器)驅動代碼
- //版權所有,盜版必究。
- //Copyright(C) 廣州市星翼電子科技有限公司 2014-2024
- //All rights reserved
- //////////////////////////////////////////////////////////////////////////////////
-
- //初始化光敏傳感器
- void Lsens_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);//使能PORTF時鐘
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//PF8 anolog輸入
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //模擬輸入引腳
- GPIO_Init(GPIOF, &GPIO_InitStructure);
- Adc3_Init();
- }
- //讀取Light Sens的值
- //0~100:0,最暗;100,最亮
- u8 Lsens_Get_Val(void)
- {
- u32 temp_val=0;
- u8 t;
- for(t=0;t<LSENS_READ_TIMES;t++)
- {
- temp_val+=Get_Adc3(LSENS_ADC_CHX); //讀取ADC值
- delay_ms(5);
- }
- temp_val/=LSENS_READ_TIMES;//得到平均值
- if(temp_val>4000)temp_val=4000;
- return (u8)(100-(temp_val/40));
- }
復制代碼
|