admin管理员组

文章数量:1516870

蓝桥杯STM32G431学习记录4——LCD的使用

LCD的配置

根据比赛提供的赛场资源数据包(G431)中的LCD_Test例程打开CubeMX生成的代码可直接使用

main.c中对LCD使用的程序编写

#include "main.h"
#include "lcd.h"/*定义lcd处理函数中使用的全局变量*/
__IO uint32_t uwTick_LCD_State_Pointer;
unsigned char Lcd_Disp_String[21];void LCD_Proc(void);LCD_Init();	//lcd初始化LCD_Clear(White);	//清屏为白色LCD_SetBackColor(White);	//设置背景颜色LCD_SetTextColor(Magenta);	//设置字体颜色int main(void)
{HAL_Init();SystemClock_Config();while (1){LCD_Proc();	//lcd处理函数}
}
void LCD_Proc(void)  //lcd处理函数
{static unsigned char count=0;	//定义静态变量if(uwTick-uwTick_LCD_State_Pointer<1000) return; //扫描时间设置为1suwTick_LCD_State_Pointer=uwTick;count++;memset(Lcd_Disp_String,0,sizeof(Lcd_Disp_String));	//将字符串清空sprintf((char*)Lcd_Disp_String, "    count num: %03d       ",count);  //sprintf格式化字符串的处理将count的值赋给数组Lcd_Disp_StringLCD_DisplayStringLine(Line0, Lcd_Disp_String);}

使用LCD的注意事项

1、在STM32G431单片机屏幕上只能显示出字符串数组中的20位,故字符串数组大小定义为21位(加上末尾‘\0’)
2、引用stdio.h头文件使用 字符串格式化函数 int sprintf(char str, const char format, …)

本文标签: 蓝桥杯STM32G431学习记录4LCD的使用