docs: 按照开发规范重构项目,完成七个环节文档整理与.xagent流程搭建
This commit is contained in:
44
Docs/60_coding/mod-lcd.md
Normal file
44
Docs/60_coding/mod-lcd.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# 编码实现 - LCD 显示与字模驱动 (docs/60_coding/mod-lcd.md)
|
||||
|
||||
本文件对应 LCD 驱动与字模渲染的具体编码实现细节。
|
||||
|
||||
## 1. 对应代码源文件
|
||||
|
||||
* [Drivers/lcd.c](file:///c:/workfile/105/stc32g12k128/Drivers/lcd.c) (LCD 初始化、SPI 数据写、画图画字函数)
|
||||
* [Drivers/lcd.h](file:///c:/workfile/105/stc32g12k128/Drivers/lcd.h) (管脚接口与画图画字声明)
|
||||
* [Drivers/lcd_font.h](file:///c:/workfile/105/stc32g12k128/Drivers/lcd_font.h) (ASCII 8x16 点阵字模与图标数据)
|
||||
|
||||
## 2. 关键代码片段与逻辑实现
|
||||
|
||||
### 2.1 局部窗口设置 (X轴偏移量修正)
|
||||
在 `lcd.c` 中配置窗口时,需要向 X 轴坐标加上 4 像素偏差:
|
||||
```c
|
||||
void LCD_SetWindow(u16 x1, u16 y1, u16 x2, u16 y2) {
|
||||
x1 += 4;
|
||||
x2 += 4;
|
||||
LCD_WriteCmd(0x2A); // Column Address Set
|
||||
LCD_WriteData(x1 >> 8);
|
||||
LCD_WriteData(x1 & 0xFF);
|
||||
LCD_WriteData(x2 >> 8);
|
||||
LCD_WriteData(x2 & 0xFF);
|
||||
|
||||
LCD_WriteCmd(0x2B); // Row Address Set
|
||||
LCD_WriteData(y1 >> 8);
|
||||
LCD_WriteData(y1 & 0xFF);
|
||||
LCD_WriteData(y2 >> 8);
|
||||
LCD_WriteData(y2 & 0xFF);
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 电池图标与百分比坐标对齐
|
||||
在 `main.c` 的时钟重绘函数中,通过以下坐标绘制电量:
|
||||
```c
|
||||
// 绘制百分比字符
|
||||
LCD_ShowString(62, 24, "85%", WHITE, BLACK);
|
||||
// 绘制电池位图
|
||||
LCD_ShowImage(92, 27, 24, 12, BATTERY_ICON, RED, BLACK);
|
||||
```
|
||||
两者 Y 轴保持 24 与 27 对齐,X 轴保持 30 像素的安全边距(62 + 3 * 8 = 86,与 92 之间有 6 像素的安全间距),防止文字错乱或重合。
|
||||
|
||||
### 2.3 字模百分号偏置
|
||||
在 `lcd_font.h` 的 ASCII 字符数组中,百分号 `%`(十进制 37,十六进制 0x25)的字模通过在字模绘制时向上平移 2 像素对齐普通数字的下基准线。
|
||||
Reference in New Issue
Block a user