在线时间1739 小时
UID3327992
ST金币3504
蝴蝶豆65
注册时间2016-11-16
该用户从未签到
论坛元老
- 最后登录
- 2021-5-10
|
继上次实现点亮TFT液晶屏并实现TF卡内图片显示。本次是实现显示TF内字库的文字。通过读取tf卡内字库文件,在液晶屏上显示。
STM32F410 Nucleo-64 驱动点亮ILI9486的TFT液晶屏
https://www.stmcu.org.cn/module/forum/thread-628139-1-1.html
【年度庆典二】+祝ST越来越好
https://www.stmcu.org.cn/module/forum/thread-628305-1-1.html
- /* type define ------------------------------------------------------------*/
- typedef struct _lcd_font
- {
- uint8_t font_height; //字库通用高度
- char * pfont_buff; //字库buff
- char * pfont_filename; //字库文件
- uint8_t (* get_font_w)(uint16_t ch); //获取指定字符宽度
- void (* draw_char)(uint16_t x,uint16_t y,uint16_t ch); //指定字符描点
- }lcd_font_t;
- typedef struct _lcd_font_display
- {
- lcd_font_t *pfont; //字库索引
- lcd_color_t font_fore; //字体前景颜色
- lcd_color_t font_back; //字体背景颜色
- uint16_t font_sx; //字符显示范围起点x
- uint16_t font_sy; //字符显示范围起点y
- uint16_t font_ex; //字符显示范围终点x
- uint16_t font_ey; //字符显示范围终点y
- }lcd_font_display_t;
- //common
- int GetGBKCode_from_sd(char *filename, uint16_t ch, uint8_t *pBuffer, uint16_t len);
- //API
- lcd_font_t * lcd_set_font( const lcd_font_t *newfont);
- lcd_font_t * lcd_get_font(void);
- void lcd_set_font_color(lcd_color_t fore, lcd_color_t back);
- lcd_color_t lcd_get_font_color_fore(void);
- lcd_color_t lcd_get_font_color_back(void);
- void lcd_set_font_window(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey);
- void lcd_disp_char_at(uint16_t usX, uint16_t usY, uint16_t cChar);
- void lcd_disp_str_at(uint16_t usX, uint16_t usY, const char *pStr);
- void lcd_font_init(void);
- //字库
- extern const lcd_font_t Font_CH16X16;
- extern const lcd_font_t Font_ASCII16X8;
- extern const lcd_font_t Font_CH24X24;
- extern const lcd_font_t Font_ASCII24X12;
- extern const lcd_font_t Font_CH32X32;
- extern const lcd_font_t Font_ASCII32X16;
- extern const lcd_font_t Font_CH40X40;
- extern const lcd_font_t Font_ASCII40X20;
- extern const lcd_font_t Font_CH48X48;
- extern const lcd_font_t Font_ASCII48X24;
复制代码- #include "lcd_driver.h"
- #include "lcd_font.h"
- lcd_font_display_t cur_lcd_font_display;
- /**
- * 设置当前字体
- * para: *newfont 新字体
- * return: none
- */
- lcd_font_t * lcd_set_font(const lcd_font_t * newfont)
- {
- lcd_font_t *oldfont;
- oldfont = cur_lcd_font_display.pfont;
- cur_lcd_font_display.pfont = (lcd_font_t *)newfont;
- return oldfont;
- }
- /**
- * 获取当前字体
- * para: none
- * return: 当前字体
- */
- lcd_font_t * lcd_get_font(void)
- {
- return cur_lcd_font_display.pfont;
- }
- /**
- * 设置当前字体颜色
- * para1: fore 前景色
- * para2: back 背景色
- * return: none
- */
- void lcd_set_font_color(lcd_color_t fore, lcd_color_t back)
- {
- cur_lcd_font_display.font_fore = fore;
- cur_lcd_font_display.font_back = back;
- }
- /**
- * 获取当前字体前景色
- * para: none
- * return: 当前字体前景色
- */
- lcd_color_t lcd_get_font_color_fore(void)
- {
- return cur_lcd_font_display.font_fore;
- }
- /**
- * 获取当前字体背景色
- * para: none
- * return: 当前字体背景色
- */
- lcd_color_t lcd_get_font_color_back(void)
- {
- return cur_lcd_font_display.font_back;
- }
- /**
- * 设置字符显示范围
- * para1: sx
- * para2: sy
- * para3: ex
- * para4: ey
- * return: none
- */
- void lcd_set_font_window(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey)
- {
- cur_lcd_font_display.font_sx = sx;
- cur_lcd_font_display.font_sy = sy;
- cur_lcd_font_display.font_ex = ex;
- cur_lcd_font_display.font_ey = ey;
- }
- /**
- * LCD 上显示字符
- * usX : 在特定扫描的方向下字符的起始 X 坐标
- * usY : 在特定扫描的方向下字符的起始 Y 坐标
- * cChar : 要显示的字符
- * 返回值 : 无
- */
- void lcd_disp_char_at(uint16_t usX, uint16_t usY, uint16_t cChar)
- {
- if((cur_lcd_font_display.pfont != NULL) && (cur_lcd_font_display.pfont->draw_char != NULL))
- {
- cur_lcd_font_display.pfont->draw_char(usX, usY, cChar);
- }
- }
- /**
- * 在 LCD 上显示英文字符串
- * usX : 在特定扫描方向下字符串的起始 X 坐标
- * usY : 在特定扫描方向下字符串的起始 Y 坐标
- * pStr : 要显示的英文字符串的首地址
- * 返回值 : 无
- */
- void lcd_disp_str_at(uint16_t usX, uint16_t usY, const char *pStr)
- {
- uint16_t w,ch;
- if(cur_lcd_font_display.pfont == NULL) return;
- while (*pStr != '\0')
- {
- if(*pStr > 126)
- {
- ch = (*pStr << 8);
- pStr++;
- ch += *pStr;
- }
- else
- {
- ch = *pStr;
- }
-
- w = cur_lcd_font_display.pfont->get_font_w(ch); //获取字符宽度
- if(ch == 0x0a)
- {
- usX = 0;
- usY += cur_lcd_font_display.pfont->font_height;
- if ((usY + cur_lcd_font_display.pfont->font_height) > LCD_H)
- {
- break;
- }
- }else if(ch != 0x0d)
- {
- lcd_disp_char_at(usX, usY, ch);
- }
-
- pStr++;
- usX += w;
- }
- }
- void lcd_font_init(void)
- {
- lcd_set_font(&Font_ASCII16X8);
- lcd_set_font_color(BLACK,WHITE);
- lcd_set_font_window(0,0,LCD_W-1,LCD_H-1);
- }
复制代码
源程序:
F410_LCD_PIC_Demo.rar
(2.55 MB, 下载次数: 7)
|
|