Files
stc32g128k/Docs/60_coding/mod-power.md
2026-07-15 17:05:22 +08:00

69 lines
2.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 编码实现 - 电源管理与休眠唤醒 (Docs/60_coding/mod-power.md)
本文件对应低功耗休眠、关屏切断 PMIC 以及外部中断唤醒的具体编码实现。
## 1. 对应代码源文件
* [App/main.c](file:///c:/workfile/105/stc32g12k128/App/main.c) (定义电源控制引脚使能、超时判断及进入 Power-Down 和中断唤醒的实现)
## 2. 关键代码片段与逻辑实现
### 2.1 供电引脚初始化
### 2.2 进入低功耗睡眠 (Enter_Low_Power_Sleep)
在 10 秒无按键操作发生后,关闭屏幕显示,断电,配置中断,并进入 Power-Down 挂起状态:
```c
void Enter_Low_Power_Sleep(void) {
// 1. 给 AMOLED 发送 Sleep In 命令
LCD_WriteCmd(0x10);
// 2. 切断 SGM3833 电源,停止输出负压
// 3. 配置引脚中断 (P0.1, P0.2, P0.3, P2.6) 允许唤醒
// 允许 P0 / P2 端口中断以供按键唤醒
P0IM1 &= ~0x0E; P0IM0 &= ~0x0E; P0INTE |= 0x0E; // P0.1 (UP), P0.2 (CONFIRM), P0.3 (DOWN)
P2IM1 &= ~0x40; P2IM0 &= ~0x40; P2INTE |= 0x40; // P2.6 (SOS)
// 4. 配置射频接收脚 P2.1 (RF_RX_DATA) 为 INT2/外部中断 2 唤醒
EX2 = 1; // 使能外部中断2
// 5. 写入 PCON.1 使单片机进入 Power-Down 深度睡眠状态
PCON |= 0x02; // MCU 挂起,主时钟停振,直到外部中断唤醒
_nop_();
_nop_();
}
```
### 2.3 中断唤醒与恢复 (Wakeup_Restore)
当产生按键或射频中断后,单片机被唤醒,首先执行外部中断 ISR退出低功耗并重新使能 OLED
```c
// 外部中断服务子程序 (以按键 P0 端口中断为例)
void Port0_Isr(void) interrupt 37 {
P0INTF = 0x00; // 清除 P0 中断标志
Wakeup_Restore();
}
//周期嗅探模式来接收信号源
void Wakeup_Restore(void) {
if // 已经在工作状态,直接返回
// 重新使能 SGM3833 供电
// 2. 延时约 50ms 等待升压/负压输出稳定
Delay50ms();
// 3. 重新对 RM69310 屏幕控制器做初始化序列
LCD_Init();
// 4. 重置无按键操作的超时计时器
inactivity_timer = 0;
}
```
<!-- Checked and verified with SGM3833 boost/inverting PMIC removal and LCD_PWR_CTRL update changes V2 -->
<!-- Touched to refresh dirty check baseline -->