Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
haoJin750TFT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时昊
haoJin750TFT
Commits
59b1636b
Commit
59b1636b
authored
Aug 16, 2024
by
张金硕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
feat:增加背光自动调节功能
parent
5c35c886
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
40 deletions
+84
-40
BackLight.c
Firmware/Source/Application/BackLight.c
+83
-40
BackLight.h
Firmware/Source/Application/BackLight.h
+1
-0
No files found.
Firmware/Source/Application/BackLight.c
View file @
59b1636b
...
...
@@ -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
;
}
/* 获取电阻值回调函数 */
...
...
Firmware/Source/Application/BackLight.h
View file @
59b1636b
...
...
@@ -23,6 +23,7 @@
void
Backlight_KL30_Wakeup_Init
(
void
);
void
BackLight_Process
(
void
);
Light_uint8_t
Backlight_SetPwmLevel
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment