Browse Source

feature: 1.将开关机引脚改为P3.2测试开关机正常 2.配置P3.2为外部中断,下降沿触发唤醒掉电模式,测试功能正常 3.实际使用有个问题是,掉电状态下需要先按一下唤醒MCU

v4-temp-lowpower
Zhangwen 2 months ago
parent
commit
e348919bb5
  1. 18
      source/app/main.c
  2. 39
      source/app/task_appstatus.c
  3. 3
      source/app/task_appstatus.h
  4. 4
      source/app/task_keystatus.c
  5. 3
      source/bsp/bsp_key.c
  6. 2
      source/bsp/bsp_key.h

18
source/app/main.c

@ -15,6 +15,8 @@ void L0_MCU_init(void)
L1_tick_init();
//开启全局中断
EA = 1;
// 外部中断初始化
INT0_Init();
// 定时器初始化
L0_timer0_Init();
//G初始化
@ -74,7 +76,10 @@ void main(void)
L0_BSP_init();
//任务初始化
L0_TASK_init();
// // // 禁用不需要的唤醒源
// WAKE_CLKO = 0x00; // 关闭所有特殊唤醒源
// // 获取mcu id
// L0_id_get_rom(G.mcu_id);
// L0_uart0_sendstr("MCU_ID = ");
@ -100,11 +105,12 @@ void main(void)
{
s_nos_tick.t1s_heartbeat = 0;//置0清空
L0_uart0_uc('.');
L0_uart0_sendstr("ADC = ");
L0_uart0_ushex(_s_task_adc.adc_val[_s_task_adc.index]);
L0_uart0_0d0a();
L0_uart0_sendstr("Vin = ");
L0_uart0_ushex(G.Vin);
L0_uart0_uchex(R.app_status);
// L0_uart0_sendstr("ADC = ");
// L0_uart0_ushex(_s_task_adc.adc_val[_s_task_adc.index]);
// L0_uart0_0d0a();
// L0_uart0_sendstr("Vin = ");
// L0_uart0_ushex(G.Vin);
// i++;
// if (i == 3)
// {

39
source/app/task_appstatus.c

@ -11,6 +11,32 @@
#include "../app/task_w600.h"
#include "../bsp/bsp_wifi.h"
// 外部中断初始化P3.2
void INT0_Init(void)
{
D_stdIO_P3(BITN2);
IT0 = 1; // 下降沿触发
EX0 = 1; // 使能INT0
}
// 掉电模式函数
void Enter_PowerDown(void)
{
// 禁用所有唤醒源
P0IE = 0x00;
P1IE = 0x00;
P2IE = 0x00;
P3IE = 0x00;
P4IE = 0x00;
P5IE = 0x00;
// 只使能P3.2唤醒
// P3IE = 0x04;
PCON |= 0x02; // 执行PD指令
_nop_();
_nop_();
}
S_TASK_APPSTATUS _s_task_appstatus;
@ -71,6 +97,12 @@ void L3_task_appstatus_handler(S_TASK_APPSTATUS *s)
Lc_delay_ms(5000);
// 语音模块关闭
L2_WT2605B_OFF();
// MCU进入掉电模式
Enter_PowerDown();
// 唤醒后绿灯亮起
L2_GREEN_LED_ON();
}
else if (s->status == POW_ON_WAIT)
{
@ -160,4 +192,11 @@ void PowerOff_judge()
L0_uart0_sendstr("R.app_status = POW_OFF!!!");
L0_uart0_0d0a();
}
}
// 外部中断0服务函数
void INT0_Isr() interrupt 0
{
// 无需任何操作,中断仅用于唤醒MCU
// 唤醒后程序从Enter_PowerDown()后的指令继续执行
}

3
source/app/task_appstatus.h

@ -21,4 +21,7 @@ extern void L3_task_AppStatus_init(void);
extern void L3_task_appstatus_handler(S_TASK_APPSTATUS *s);
extern void PowerOff_judge();
extern void INT0_Init(void);
extern void Enter_PowerDown(void);
#endif // #ifndef

4
source/app/task_keystatus.c

@ -44,6 +44,7 @@ void L3_task_keystatus_handler(S_TASK_KEYSTATUS *s)
TTSS_Task_step(D_task_KEY_DETECT)
if(L2_ReadKey3() == Key_Down)
{
L0_uart0_uc('!');
R.Operate_time = D_sys_now;
if (s->Key3_Down_Begin_Time == 0)
{
@ -55,14 +56,17 @@ void L3_task_keystatus_handler(S_TASK_KEYSTATUS *s)
// L0_uart0_ulhex(diff);
if (diff >= LongKey_PWR_MSeconds/JIFFIES && s->Key3_handled == 0)
{
L0_uart0_uc('@');
if (R.app_status == POW_OFF)
{
L0_uart0_uc('#');
R.app_status = POW_ON_WAIT;
s->Key3_Down_Begin_Time = 0;
s->Key3_handled = 1;
}
else
{
L0_uart0_uc('$');
R.app_status = POW_OFF;
s->Key3_Down_Begin_Time = 0;
s->Key3_handled = 1;

3
source/bsp/bsp_key.c

@ -4,7 +4,8 @@ void L2_key_init()
{
D_stdIO_P2(BITN1);
D_stdIO_P2(BITN0);//准双向口
D_stdIO_P0(BITN2);
// D_stdIO_P0(BITN2);
D_stdIO_P3(BITN2);
//初始化为高电平
Key1 = Key2 = Key3 = 1;

2
source/bsp/bsp_key.h

@ -9,7 +9,7 @@
#define Key1 P21 //音量增大
#define Key2 P20 //音量减小
#define Key3 P02 //开关机
#define Key3 P32 //开关机
// #define Key (key1 && key2 && key3)

Loading…
Cancel
Save