void LCD_Display_min(uint16_t min)//LCD显示屏显示分钟 { int min_u; int min_t; min_u=min/10; min_t=min%10; switch(min_t) { case 0: LCDSEG14 = 0x07; LCDSEG15 = 0x0D; break; case 1: LCDSEG14= 0x00; LCDSEG15 = 0x05; break; case 2: LCDSEG14 = 0x05; LCDSEG15 = 0x0B; break; case 3: LCDSEG14 = 0x01; LCDSEG15 = 0x0F; break; case 4: LCDSEG14 = 0x02; LCDSEG15 = 0x07; break; case 5: LCDSEG14 = 0x03; LCDSEG15 = 0x0E; break; case 6: LCDSEG14 = 0x07; LCDSEG15 = 0x0E; break; case 7: LCDSEG14 = 0x01; LCDSEG15 = 0x05; break; case 8: LCDSEG14 = 0x07; LCDSEG15 = 0x0F; break; case 9: LCDSEG14 = 0x03; LCDSEG15 = 0x0F; break; } switch(min_u) { case 0: LCDSEG12 = 0x07; LCDSEG13 = 0x0D; break; case 1: LCDSEG12 = 0x00; LCDSEG13 = 0x05; break; case 2: LCDSEG12 = 0x05; LCDSEG13 = 0x0B; break; case 3: LCDSEG12 = 0x01; LCDSEG13 = 0x0F; break; case 4: LCDSEG12 = 0x02; LCDSEG13 = 0x07; break; case 5: LCDSEG12 = 0x03; LCDSEG13 = 0x0E; break; case 6: LCDSEG12 = 0x07; LCDSEG13 = 0x0E; break; }这段代码优化一下
时间: 2024-02-14 16:18:18 浏览: 94
LCD的显示函数
5星 · 资源好评率100%
这段代码可以进行优化,可以使用一个数组来存储每个数字对应的LCD段码,然后通过计算得到每个数字的位数,再取出对应的LCD段码进行显示。
优化后的代码如下:
```
const uint8_t digits[10][2] = {
{0x07, 0x0D}, // 0
{0x00, 0x05}, // 1
{0x05, 0x0B}, // 2
{0x01, 0x0F}, // 3
{0x02, 0x07}, // 4
{0x03, 0x0E}, // 5
{0x07, 0x0E}, // 6
{0x01, 0x05}, // 7
{0x07, 0x0F}, // 8
{0x03, 0x0F} // 9
};
void LCD_Display_min(uint16_t min) {
int min_u = min / 10;
int min_t = min % 10;
LCDSEG12 = digits[min_u][0];
LCDSEG13 = digits[min_u][1];
LCDSEG14 = digits[min_t][0];
LCDSEG15 = digits[min_t][1];
}
```
这样的话,代码更加简洁,并且易于维护。
阅读全文