Commit 59b1636b authored by 张金硕's avatar 张金硕

feat:增加背光自动调节功能

parent 5c35c886
......@@ -63,57 +63,56 @@ void Data_Light_Res_service(Light_uint8_t deltaTime)//获取光感阻值,并
uint8_t i, j;
uint32_t temp32;
static uint16_t timeCount = 0;
if(GET_Backlight() == Backlight_ATUO)
if (timeCount >= LIGHT_DATA_TIME)
{
if (timeCount >= LIGHT_DATA_TIME)
timeCount = 0;
if (NtcDataCount < LIGHT_DATA_NUM)
{
timeCount = 0;
if (NtcDataCount < LIGHT_DATA_NUM)
/*获取光敏电阻*/
LightRes = ADC_Read_Signal(ADC_CH_LIGHT_SENSITIVE); // ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if (LightRes < 32000)
{
/*获取光敏电阻*/
LightRes = ADC_Read_Signal(ADC_CH_LIGHT_SENSITIVE); // ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if (LightRes < 32000)
{
if (LightRes % 10 >= 5)
{
LightRes += 5;
}
}
else
if (LightRes % 10 >= 5)
{
LightRes = 32000;
LightRes += 5;
}
/*由小到大插入数据*/
for (i = 0; i < NtcDataCount; i++)
{
if (LightRes < NtcData[i])
{
break;
}
}
for (j = NtcDataCount; j > i; j--)
{
NtcData[j] = NtcData[j - 1];
}
NtcData[i] = LightRes;
NtcDataCount++;
}
else
{
/*一组数据采集完毕,取中间部分计算平均值*/
temp32 = 0;
for (i = LIGHT_CAL_START; i < LIGHT_CAL_END; i++)
LightRes = 32000;
}
/*由小到大插入数据*/
for (i = 0; i < NtcDataCount; i++)
{
if (LightRes < NtcData[i])
{
temp32 += NtcData[i];
break;
}
LightR = (uint16_t) (temp32 / (LIGHT_CAL_END - LIGHT_CAL_START));
NtcDataCount = 0;
LightADCompleteFlg = 1;
}
for (j = NtcDataCount; j > i; j--)
{
NtcData[j] = NtcData[j - 1];
}
NtcData[i] = LightRes;
NtcDataCount++;
}
timeCount += deltaTime;
else
{
/*一组数据采集完毕,取中间部分计算平均值*/
temp32 = 0;
for (i = LIGHT_CAL_START; i < LIGHT_CAL_END; i++)
{
temp32 += NtcData[i];
}
LightR = (uint16_t) (temp32 / (LIGHT_CAL_END - LIGHT_CAL_START));
NtcDataCount = 0;
LightADCompleteFlg = 1;
}
}
timeCount += deltaTime;
if(GET_Backlight() == Backlight_ATUO)
{
if(LightADCompleteFlg)
{
if(LightR <= 800)
......@@ -145,6 +144,29 @@ void Data_Light_Res_service(Light_uint8_t deltaTime)//获取光感阻值,并
}
}
else if(Menu_Item_Select_Get(MENU_ITEM_SELECT_AUTO))
{
if(Backlight_SetPwmLevel() == 1U)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 100);
}
else if(Backlight_SetPwmLevel() == 2U)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 200);
}
else if(Backlight_SetPwmLevel() == 3U)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 400);
}
else if(Backlight_SetPwmLevel() == 4U)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 600);
}
else if(Backlight_SetPwmLevel() == 5U)
{
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 800);
}
}
else
{
BackLight_Process();
......@@ -209,8 +231,29 @@ Light_uint8_t Backlight_SetPwmEn(void)
/* 背光等级回调函数 */
Light_uint8_t Backlight_SetPwmLevel(void)
{
Light_uint8_t Backlight_PwmLevel;
return 1;
if(LightR > 0 && LightR <= 400)
{
Backlight_PwmLevel = 1U;
}
else if(LightR > 400 && LightR <= 800)
{
Backlight_PwmLevel = 2U;
}
else if(LightR > 800 && LightR <= 1400)
{
Backlight_PwmLevel = 3U;
}
else if(LightR > 1400 && LightR <= 2000)
{
Backlight_PwmLevel = 4U;
}
else if(LightR > 2000 && LightR <= 2600)
{
Backlight_PwmLevel = 5U;
}
return Backlight_PwmLevel;
}
/* 获取电阻值回调函数 */
......
......@@ -23,6 +23,7 @@
void Backlight_KL30_Wakeup_Init(void);
void BackLight_Process(void);
Light_uint8_t Backlight_SetPwmLevel(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment