Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
陈敏
STC_power
Commits
82bfdbee
Commit
82bfdbee
authored
1 year ago
by
陈敏
Browse files
Options
Download
Email Patches
Plain Diff
按键开关机功能版本V0.1
parent
4fd625b9
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
Keilv5/outMCP16502/Objects/STC8H1K08.hex
+341
-349
Keilv5/outMCP16502/Objects/STC8H1K08.hex
Source/App/APP.c
+54
-19
Source/App/APP.c
Source/App/System_init.c
+13
-7
Source/App/System_init.c
Source/App/Task.c
+1
-1
Source/App/Task.c
Source/App/event.h
+2
-2
Source/App/event.h
Source/App/main.c
+1
-0
Source/App/main.c
Source/Drive/STC8G_H_UART.h
+1
-1
Source/Drive/STC8G_H_UART.h
Source/Drive/ql_MCP16502.c
+48
-17
Source/Drive/ql_MCP16502.c
Source/Drive/ql_MCP16502.h
+0
-1
Source/Drive/ql_MCP16502.h
with
461 additions
and
397 deletions
+461
-397
Keilv5/outMCP16502/Objects/STC8H1K08.hex
+
341
-
349
View file @
82bfdbee
This diff is collapsed.
Click to expand it.
Source/App/APP.c
+
54
-
19
View file @
82bfdbee
...
...
@@ -38,7 +38,7 @@ uint8_t sys_idle_cnt;
#define MCP_STATE_SLEEP (2)
#define MCP_SLEEP_CNT (50)
#define SYS_SLEEP_CNT (
2
0)
#define SYS_SLEEP_CNT (
1
0)
#define sys_exit_idle() clean_sys_idle_cnt()
#define clean_sys_idle_cnt() (sys_idle_cnt = 0)
...
...
@@ -56,10 +56,10 @@ void APP_config(void)
//========================================================================
void
sys_idle_handle
(
void
)
{
PrintString1
(
"idle"
);
if
(
sys_idle_cnt
<
SYS_SLEEP_CNT
)
{
sys_idle_cnt
++
;
}
else
{
// PrintString1("SYS_EVENT_SLEEP\r\n");
set_sys_event
(
SYS_EVENT_SLEEP
);
clean_sys_idle_cnt
();
}
...
...
@@ -82,6 +82,7 @@ void sys_abnormal_handle(void)
delay_ms
(
1
);
PrintString1
(
"weak up!"
);
}
clean_all_sys_event
();
}
}
...
...
@@ -95,16 +96,16 @@ void MCP16502_handle(void)
switch
(
MCP_work_state
)
{
case
MCP_STATE_OFF
:
if
(
get_user_event
(
USER_EVENT_
KEY_CLICK
,
true
))
if
(
get_user_event
(
USER_EVENT_
PWR_ON
,
true
))
{
MCP_TURNON
();
MCP_TURNON
();
MCP_work_state
=
MCP_STATE_ON
;
}
break
;
case
MCP_STATE_ON
:
if
(
get_user_event
(
USER_EVENT_
KEY_CLICK
,
true
))
if
(
get_user_event
(
USER_EVENT_
SHORT_PRESS
,
true
))
{
MCP_TURNOFF
();
MCP_TURNOFF
();
MCP_work_state
=
MCP_STATE_OFF
;
}
...
...
@@ -118,20 +119,21 @@ void MCP16502_handle(void)
}
break
;
case
MCP_STATE_SLEEP
:
if
(
get_user_event
(
USER_EVENT_
KEY_CLICK
,
true
))
if
(
get_user_event
(
USER_EVENT_
SHORT_PRESS
,
true
))
{
MCP_TURNOFF
();
MCP_TURNOFF
();
MCP_work_state
=
MCP_STATE_OFF
;
}
if
(
get_user_event
(
USER_EVENT_LONG_PRESS
,
true
))
{
MCP_TURNOFF
();
MCP_TURNOFF
();
MCP_work_state
=
MCP_STATE_OFF
;
}
break
;
default:
break
;
}
clean_all_user_event
();
}
//========================================================================
...
...
@@ -139,8 +141,9 @@ void MCP16502_handle(void)
//========================================================================
void
key_press_handle
(
void
)
{
static
uint8_t
pwr_state
,
key_no_release
,
pwr_cnt
=
0
;
static
uint16_t
key_press_cnt
;
static
uint
16
_t
read_cnt
;
static
uint
8
_t
read_cnt
;
uint8_t
state
=
0
;
if
(
++
read_cnt
>
6
)
...
...
@@ -151,26 +154,58 @@ void key_press_handle(void)
if
(
state
&
0x20
)
{
PrintString1
(
" off
\r\n
"
);
set_user_event
(
USER_EVENT_LONG_PRESS
);
}
pwr_state
=
0
;
}
else
{
if
(
KEY_STATUS
==
KEY_PRESS
)
{
if
(
key_press_cnt
<
65530
)
key_press_cnt
++
;
P13
=
1
;
sys_exit_idle
();
if
(
key_press_cnt
==
2
)
if
(
key_press_cnt
==
100
&&
MCP_work_state
==
MCP_STATE_OFF
)
{
key_no_release
=
1
;
set_user_event
(
USER_EVENT_PWR_ON
);
}
if
(
key_press_cnt
>
400
&&
key_no_release
==
0
&&
MCP_work_state
!=
MCP_STATE_OFF
)
{
set_user_event
(
USER_EVENT_KEY_CLICK
)
;
}
}
pwr_state
++
;
}
}
else
{
// if (key_press_cnt > 2 && key_press_cnt < 200)
// {
// set_user_event(USER_EVENT_KEY_CLICK);
// }
key_no_release
=
0
;
P13
=
0
;
key_press_cnt
=
0
;
}
}
if
(
P12
&&
pwr_cnt
<
200
)
{
pwr_cnt
++
;
}
if
(
!
P12
)
{
pwr_cnt
=
0
;
}
if
(
P12
==
1
&&
pwr_cnt
==
10
)
{
pwr_state
=
1
;
}
else
if
(
P12
==
0
&&
pwr_state
==
1
)
{
pwr_state
=
0
;
set_user_event
(
USER_EVENT_SHORT_PRESS
);
}
else
if
(
pwr_state
>
1
)
{
pwr_state
=
0
;
set_user_event
(
USER_EVENT_SHORT_PRESS
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Source/App/System_init.c
+
13
-
7
View file @
82bfdbee
...
...
@@ -41,6 +41,8 @@ void GPIO_config(void)
// P6_MODE_IO_PU(GPIO_Pin_All); //P6 设置为准双向口
// P7_MODE_IO_PU(GPIO_Pin_All); //P7 设置为准双向口
P3_MODE_IN_HIZ
(
GPIO_Pin_4
);
P1_MODE_IN_HIZ
(
GPIO_Pin_2
);
P1_MODE_OUT_PP
(
GPIO_Pin_3
);
P3_MODE_OUT_PP
(
GPIO_Pin_3
);
P3_MODE_OUT_PP
(
GPIO_Pin_6
);
P1_MODE_OUT_OD
(
GPIO_Pin_4
|
GPIO_Pin_5
);
...
...
@@ -124,14 +126,14 @@ void UART_config(void)
COMx_InitStructure
.
UART_RxEnable
=
ENABLE
;
//接收允许, ENABLE或DISABLE
COMx_InitStructure
.
BaudRateDouble
=
DISABLE
;
//波特率加倍, ENABLE或DISABLE
UART_Configuration
(
UART1
,
&
COMx_InitStructure
);
//初始化串口1 UART1,UART2,UART3,UART4
NVIC_UART1_Init
(
DIS
ABLE
,
Priority_1
);
//中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
NVIC_UART1_Init
(
EN
ABLE
,
Priority_1
);
//中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
COMx_InitStructure
.
UART_Mode
=
UART_8bit_BRTx
;
//模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
COMx_InitStructure
.
UART_BRT_Use
=
BRT_Timer2
;
//选择波特率发生器, BRT_Timer2 (注意: 串口2固定使用BRT_Timer2, 所以不用选择)
COMx_InitStructure
.
UART_BaudRate
=
115200ul
;
//波特率, 110 ~ 115200
COMx_InitStructure
.
UART_RxEnable
=
ENABLE
;
//接收允许, ENABLE或DISABLE
UART_Configuration
(
UART2
,
&
COMx_InitStructure
);
//初始化串口2 USART1,USART2,USART3,USART4
NVIC_UART2_Init
(
DIS
ABLE
,
Priority_2
);
//中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
//
COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
//
COMx_InitStructure.UART_BRT_Use = BRT_Timer2; //选择波特率发生器, BRT_Timer2 (注意: 串口2固定使用BRT_Timer2, 所以不用选择)
//
COMx_InitStructure.UART_BaudRate = 115200ul; //波特率, 110 ~ 115200
//
COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE
//
UART_Configuration(UART2, &COMx_InitStructure); //初始化串口2 USART1,USART2,USART3,USART4
//
NVIC_UART2_Init(
EN
ABLE,Priority_2); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
}
//========================================================================
...
...
@@ -236,6 +238,9 @@ void Switch_config(void)
//========================================================================
void
SYS_Init
(
void
)
{
WDT_InitTypeDef
wtd
=
{
ENABLE
,
WDT_IDLE_RUN
,
WDT_SCALE_16
};
GPIO_config
();
Timer_config
();
// ADC_config();
...
...
@@ -248,5 +253,6 @@ void SYS_Init(void)
EA
=
1
;
APP_config
();
WDT_Inilize
(
&
wtd
);
}
This diff is collapsed.
Click to expand it.
Source/App/Task.c
+
1
-
1
View file @
82bfdbee
...
...
@@ -21,7 +21,7 @@ static TASK_COMPONENTS idata Task_Comps[]=
{
//状态 计数 周期 函数
// {0, 250, 250, Sample_Lamp}, /* task 1 Period: 250ms */
{
0
,
5
,
5
,
key_press_handle
},
/* task 2 Period: 5ms */
{
0
,
10
,
10
,
key_press_handle
},
/* task 2 Period: 5ms */
{
0
,
10
,
10
,
MCP16502_handle
},
/* task 3 Period: 10ms */
{
0
,
100
,
100
,
sys_idle_handle
},
/* task 4 Period: 100ms */
// {0, 1, 1, Sample_I2C_PS}, /* task 5 Period: 1ms */
...
...
This diff is collapsed.
Click to expand it.
Source/App/event.h
+
2
-
2
View file @
82bfdbee
...
...
@@ -12,9 +12,9 @@
// macro define
//========================================================================
#define USER_EVENT_NONE (0 << 0)
#define USER_EVENT_
KEY_CLICK
(1 << 0)
#define USER_EVENT_
SHORT_PRESS
(1 << 0)
#define USER_EVENT_LONG_PRESS (1 << 1)
#define USER_EVENT_
3
(1 << 2)
#define USER_EVENT_
PWR_ON
(1 << 2)
#define USER_EVENT_4 (1 << 3)
#define USER_EVENT_5 (1 << 4)
#define USER_EVENT_6 (1 << 5)
...
...
This diff is collapsed.
Click to expand it.
Source/App/main.c
+
1
-
0
View file @
82bfdbee
...
...
@@ -8,6 +8,7 @@ void main(void)
{
Task_Pro_Handler_Callback
();
sys_abnormal_handle
();
WDT_Clear
();
MCU_IDLE
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Source/Drive/STC8G_H_UART.h
+
1
-
1
View file @
82bfdbee
...
...
@@ -36,7 +36,7 @@
//========================================================================
#define UART1 1
#define UART2 2
//
#define UART2 2
//#define UART3 3
//#define UART4 4
...
...
This diff is collapsed.
Click to expand it.
Source/Drive/ql_MCP16502.c
+
48
-
17
View file @
82bfdbee
...
...
@@ -4,7 +4,8 @@
#else
#include
"STC8G_H_Soft_I2C.h"
#endif
#include
"STC8G_H_Delay.h"
#include
"STC8G_H_UART.h"
//========================================================================
// @brief: write a byte to a designated register.
// @param: addr: designated register address
...
...
@@ -125,8 +126,36 @@ void MCP16502_change_ouput(uint8_t channel_addr,uint8_t target_vol)
// @param: None.
// @return: system state mask.
//========================================================================
#define soft_reset() IAP_CONTR = IAP_CONTR | 0x20
uint8_t
MCP16502_read_state
(
void
)
{
uint8_t
buck1
,
buck2
,
buck3
,
buck4
;
// buck1 = MCP16502_single_read(STS_B1);
// buck2 = MCP16502_single_read(STS_B2);
// buck3 = MCP16502_single_read(STS_B3);
// buck4 = MCP16502_single_read(STS_B4);
// if (buck1 & 0xc0)
// {
// PrintString1("bcuk1\r\n");
// soft_reset();
// }
// if (buck2 & 0xc0)
// {
// PrintString1("buck2\r\n");
// soft_reset();
// }
// if (buck3 & 0xc0)
// {
// PrintString1("buck3\r\n");
// soft_reset();
// }
// if (buck4 & 0xc0)
// {
// PrintString1("buck4\r\n");
// soft_reset();
// }
return
MCP16502_single_read
(
STS_SYS
);
}
...
...
@@ -138,9 +167,7 @@ uint8_t MCP16502_read_state(void)
void
MCP16502_init
(
void
)
{
uint8_t
temp
=
0
;
MCP_TURNOFF
();
MCP_TURNOFF
();
temp
=
MCP16502_single_read
(
LDO1_SEQ
);
temp
=
temp
&
0xC7
;
MCP16502_single_write
(
LDO1_SEQ
,
temp
);
...
...
@@ -178,23 +205,27 @@ void MCP16502_init(void)
MCP16502_single_write
(
OUT3_A
,
temp
);
MCP16502_single_write
(
OUT3_LPM
,
temp
);
temp
=
MCP16502_single_read
(
OUT2_
CFG
);
//BUCK2 output enable
temp
=
temp
|
0x0
3
;
MCP16502_single_write
(
OUT2_
CFG
,
temp
);
temp
=
MCP16502_single_read
(
OUT2_
SEQ
);
//BUCK2 output enable
temp
=
temp
|
0x0
8
;
MCP16502_single_write
(
OUT2_
SEQ
,
temp
);
temp
=
MCP16502_single_read
(
OUT3_
CFG
);
//BUCK3 output enable
temp
=
temp
|
0x0
3
;
MCP16502_single_write
(
OUT3_
CFG
,
temp
);
temp
=
MCP16502_single_read
(
OUT3_
SEQ
);
//BUCK3 output enable
temp
=
temp
|
0x0
8
;
MCP16502_single_write
(
OUT3_
SEQ
,
temp
);
temp
=
MCP16502_single_read
(
OUT4_
CFG
);
//BUCK4 output enable
temp
=
temp
|
0x0
3
;
MCP16502_single_write
(
OUT4_
CFG
,
temp
);
temp
=
MCP16502_single_read
(
OUT4_
SEQ
);
//BUCK4 output enable
temp
=
temp
|
0x0
8
;
MCP16502_single_write
(
OUT4_
SEQ
,
temp
);
temp
=
MCP16502_single_read
(
OUT1_
CFG
);
//BUCK1 output enable
temp
=
temp
|
0x0
3
;
MCP16502_single_write
(
OUT1_
CFG
,
temp
);
temp
=
MCP16502_single_read
(
OUT1_
SEQ
);
//BUCK1 output enable
temp
=
temp
|
0x0
8
;
MCP16502_single_write
(
OUT1_
SEQ
,
temp
);
temp
=
MCP16502_single_read
(
LDO1_CFG
);
//LDO1 output disable
temp
=
temp
|
0x
03
;
temp
=
temp
&
0x
FC
;
MCP16502_single_write
(
LDO1_CFG
,
temp
);
temp
=
MCP16502_single_read
(
SYS_TMG
);
temp
=
(
temp
&
0x3F
)
|
0x80
;
MCP16502_single_write
(
SYS_TMG
,
temp
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Source/Drive/ql_MCP16502.h
+
0
-
1
View file @
82bfdbee
...
...
@@ -97,5 +97,4 @@ uint8_t MCP16502_single_read(uint8_t addr);
void
MCP16502_change_ouput
(
uint8_t
channel_addr
,
uint8_t
target_vol
);
uint8_t
MCP16502_read_state
(
void
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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