docs: restructure framework, extract app execution module, group event collection & align GPIOs

This commit is contained in:
2026-07-10 10:47:00 +08:00
parent a04ea5fb51
commit b640fa25ae
24 changed files with 428 additions and 213 deletions

View File

@@ -9,20 +9,20 @@
## 2. 关键代码片段与逻辑实现
### 2.1 驱动初始化与管脚分配
WS2812B 输入脚接在单片机物理引脚 `LED_RGB` (`P2.6`)
WS2812B 输入脚接在单片机物理引脚 `LED_RGB` (`P2.3`)
```c
sbit WS2812_DI = P2^6; // Pin 27
sbit WS2812_DI = P2^3; // Pin 24
void WS2812_Init(void) {
// P2.6 (LED_RGB) 配置为推挽输出,默认输出低电平 0
P2M1 &= ~(1 << 6);
P2M0 |= (1 << 6);
// P2.3 (LED_RGB) 配置为推挽输出,默认输出低电平 0
P2M1 &= ~(1 << 3);
P2M0 |= (1 << 3);
WS2812_DI = 0;
}
```
### 2.2 驱动防噪声发送 (WS2812_Write24Bit)
由于马达引脚占用 `P2.4` (Pin 25),为了规避马达震动时的共地杂噪,在串行输出数据期间关闭总中断并将马达引脚 `P2.4` 设为高阻输入。
由于马达引脚占用 `P2.5` (Pin 26),为了规避马达震动时的共地杂噪,在串行输出数据期间关闭总中断并将马达引脚 `P2.5` 设为高阻输入。
展宽 LUT 定义:
```c
const u16 code SPI_LUT[16] = {
@@ -47,9 +47,9 @@ void WS2812_Write24Bit(u8 g, u8 r, u8 b) {
EA = 0; // 关中断保证串行传输的连续性
// 配置 P2.4 (MOTOR_PWM) 为高阻输入模式,屏蔽共地马达干扰
P2M1 |= (1 << 4);
P2M0 &= ~(1 << 4);
// 配置 P2.5 (MOTOR_PWM) 为高阻输入模式,屏蔽共地马达干扰
P2M1 |= (1 << 5);
P2M0 &= ~(1 << 5);
SPSTAT = 0xC0; // 清除 SPI 状态寄存器
SPDAT = b0; // 发送数据
@@ -81,9 +81,9 @@ void WS2812_Write24Bit(u8 g, u8 r, u8 b) {
SPCTL = 0x90; // 关闭 SPI 硬件使能
WS2812_DI = 0;
// 恢复 P2.4 (MOTOR_PWM) 为推挽输出,恢复马达控制
P2M1 &= ~(1 << 4);
P2M0 |= (1 << 4);
// 恢复 P2.5 (MOTOR_PWM) 为推挽输出,恢复马达控制
P2M1 &= ~(1 << 5);
P2M0 |= (1 << 5);
MOTOR = 0; // 确保马达断开
EA = 1; // 恢复中断