【备赛蓝桥杯嵌入式(G431-HAL库)】LCD
01 基本使用
从资源包里拷贝lcd.h
和lcd.c
进入工程文件
//初始化,颜色自定
//LCD长宽为240x320
LCD_Init();
LCD_Clear(Black);
LCD_SetBackColor(Black);
LCD_SetTextColor(White);//按行显示
LCD_DisplayStringLine(Line0,(uint8_t*)TextBuff);
//arg1:Line0到Line9 也可以写成24*i(i从0开始)
//arg2:TextBuff 最多为20个空格
02 高亮
//有两种方式,一种是亮背景,一种亮文字
//所选中的高亮行数 = 首个亮的行 + 间隔 x 行号id
void Disp(){uint8_t i;for(i = 0;i < 10;++i){if((24 * i) == (Line3 + 48 * item_index)){LCD_SetBackColor(0x1e90);LCD_SetTextColor(Red);}else{LCD_SetBackColor(Black);LCD_SetTextColor(White);}switch(24*i){case Line0:case Line2:case Line4:case Line6:case Line8:sprintf(TextBuff," ");break;case Line1:sprintf(TextBuff," ItemMenu ");break;case Line3:sprintf(TextBuff," Item1 ");break;case Line5:sprintf(TextBuff," Item2 ");break;case Line7:sprintf(TextBuff," Item3 ");break;case Line9:sprintf(TextBuff," Item4 ");break;}LCD_DisplayStringLine(24*i,(uint8_t*)TextBuff);LCD_SetBackColor(Black);}
}
03 与LED冲突的解决方法
打开lcd.h
文件
找到以下三个函数(即底层的写函数)
void LCD_WriteReg(u8 Reg,u16 LCD_RegValue)
void LCD_WriteRAM_Prepare(void)
void LCD_WriteRAM(u16 RGB_Code)
在这三个函数加上以下内容:
开头:u16 pcout = GPIOC->ODR
结尾:GPIOC->ODR = pcout