请选择 进入手机版 | 继续访问电脑版
搜索
查看: 1524|回复: 5

[原创] STM32F410 Nucleo-64 通过读TF卡内字库在TFT屏上显示汉字

[复制链接]

该用户从未签到

10

主题

1665

帖子

65

蝴蝶豆

论坛元老

最后登录
2021-5-10
发表于 2021-1-9 23:36:08 | 显示全部楼层 |阅读模式
  继上次实现点亮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


1.jpg



x.jpg

  1. /* type define ------------------------------------------------------------*/
  2. typedef        struct _lcd_font
  3. {
  4.         uint8_t                font_height;                //字库通用高度
  5.         char                * pfont_buff;                 //字库buff
  6.     char        * pfont_filename;   //字库文件
  7.         uint8_t                (* get_font_w)(uint16_t ch);                //获取指定字符宽度
  8.         void        (* draw_char)(uint16_t x,uint16_t y,uint16_t ch);        //指定字符描点
  9. }lcd_font_t;

  10. typedef        struct _lcd_font_display
  11. {
  12.         lcd_font_t                *pfont;                //字库索引

  13.     lcd_color_t     font_fore;      //字体前景颜色
  14.     lcd_color_t     font_back;      //字体背景颜色

  15.         uint16_t            font_sx;                //字符显示范围起点x
  16.         uint16_t            font_sy;                //字符显示范围起点y
  17.         uint16_t            font_ex;                //字符显示范围终点x
  18.         uint16_t            font_ey;                //字符显示范围终点y

  19. }lcd_font_display_t;

  20. //common
  21. int GetGBKCode_from_sd(char *filename, uint16_t ch, uint8_t *pBuffer, uint16_t len);

  22. //API
  23. lcd_font_t * lcd_set_font( const  lcd_font_t *newfont);
  24. lcd_font_t * lcd_get_font(void);

  25. void lcd_set_font_color(lcd_color_t fore, lcd_color_t back);
  26. lcd_color_t  lcd_get_font_color_fore(void);
  27. lcd_color_t  lcd_get_font_color_back(void);


  28. void  lcd_set_font_window(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey);


  29. void lcd_disp_char_at(uint16_t usX, uint16_t usY,  uint16_t cChar);
  30. void lcd_disp_str_at(uint16_t usX, uint16_t usY, const char *pStr);

  31. void lcd_font_init(void);

  32. //字库
  33. extern const lcd_font_t Font_CH16X16;
  34. extern const lcd_font_t Font_ASCII16X8;
  35. extern const lcd_font_t Font_CH24X24;
  36. extern const lcd_font_t Font_ASCII24X12;
  37. extern const lcd_font_t Font_CH32X32;
  38. extern const lcd_font_t Font_ASCII32X16;
  39. extern const lcd_font_t Font_CH40X40;
  40. extern const lcd_font_t Font_ASCII40X20;
  41. extern const lcd_font_t Font_CH48X48;
  42. extern const lcd_font_t Font_ASCII48X24;
复制代码
  1. #include "lcd_driver.h"
  2. #include "lcd_font.h"

  3. lcd_font_display_t       cur_lcd_font_display;

  4. /**
  5. * 设置当前字体
  6. * para: *newfont 新字体
  7. * return:  none
  8. */
  9. lcd_font_t * lcd_set_font(const lcd_font_t *  newfont)
  10. {
  11.     lcd_font_t *oldfont;
  12.     oldfont = cur_lcd_font_display.pfont;
  13.     cur_lcd_font_display.pfont = (lcd_font_t *)newfont;
  14.     return oldfont;
  15. }

  16. /**
  17. * 获取当前字体
  18. * para: none
  19. * return: 当前字体
  20. */
  21. lcd_font_t * lcd_get_font(void)
  22. {
  23.     return cur_lcd_font_display.pfont;
  24. }

  25. /**
  26. * 设置当前字体颜色
  27. * para1: fore 前景色
  28. * para2: back 背景色
  29. * return:  none
  30. */
  31. void lcd_set_font_color(lcd_color_t fore, lcd_color_t back)
  32. {
  33.     cur_lcd_font_display.font_fore = fore;
  34.     cur_lcd_font_display.font_back = back;
  35. }

  36. /**
  37. * 获取当前字体前景色
  38. * para: none
  39. * return: 当前字体前景色
  40. */
  41. lcd_color_t  lcd_get_font_color_fore(void)
  42. {
  43.     return cur_lcd_font_display.font_fore;
  44. }

  45. /**
  46. * 获取当前字体背景色
  47. * para: none
  48. * return: 当前字体背景色
  49. */
  50. lcd_color_t  lcd_get_font_color_back(void)
  51. {
  52.     return cur_lcd_font_display.font_back;
  53. }

  54. /**
  55. * 设置字符显示范围
  56. * para1: sx
  57. * para2: sy
  58. * para3: ex
  59. * para4: ey
  60. * return: none
  61. */
  62. void  lcd_set_font_window(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey)
  63. {
  64.     cur_lcd_font_display.font_sx = sx;
  65.     cur_lcd_font_display.font_sy = sy;
  66.     cur_lcd_font_display.font_ex = ex;
  67.     cur_lcd_font_display.font_ey = ey;
  68. }


  69. /**
  70. *  LCD 上显示字符
  71. * usX : 在特定扫描的方向下字符的起始 X 坐标
  72. * usY : 在特定扫描的方向下字符的起始 Y 坐标
  73. * cChar : 要显示的字符
  74. * 返回值 : 无
  75. */
  76. void lcd_disp_char_at(uint16_t usX, uint16_t usY, uint16_t cChar)
  77. {   
  78.     if((cur_lcd_font_display.pfont != NULL) && (cur_lcd_font_display.pfont->draw_char != NULL))
  79.     {
  80.         cur_lcd_font_display.pfont->draw_char(usX, usY, cChar);
  81.     }
  82. }

  83. /**
  84. * 在 LCD 上显示英文字符串
  85. * usX : 在特定扫描方向下字符串的起始 X 坐标
  86. * usY : 在特定扫描方向下字符串的起始 Y 坐标
  87. * pStr : 要显示的英文字符串的首地址
  88. * 返回值 : 无
  89. */

  90. void lcd_disp_str_at(uint16_t usX, uint16_t usY, const char *pStr)
  91. {
  92.     uint16_t  w,ch;

  93.     if(cur_lcd_font_display.pfont == NULL)  return;

  94.     while (*pStr != '\0')
  95.     {
  96.         if(*pStr > 126)
  97.         {
  98.             ch = (*pStr << 8);
  99.             pStr++;  
  100.             ch += *pStr;  
  101.         }
  102.         else
  103.         {
  104.             ch = *pStr;
  105.         }
  106.         
  107.         w = cur_lcd_font_display.pfont->get_font_w(ch);  //获取字符宽度

  108.         if(ch == 0x0a)
  109.         {
  110.             usX = 0;
  111.             usY += cur_lcd_font_display.pfont->font_height;

  112.             if ((usY + cur_lcd_font_display.pfont->font_height) > LCD_H)
  113.             {
  114.                 break;
  115.             }
  116.         }else if(ch != 0x0d)
  117.         {
  118.             lcd_disp_char_at(usX, usY, ch);
  119.         }
  120.    
  121.         pStr++;
  122.         usX += w;
  123.     }
  124. }


  125. void lcd_font_init(void)
  126. {
  127.     lcd_set_font(&Font_ASCII16X8);
  128.     lcd_set_font_color(BLACK,WHITE);
  129.     lcd_set_font_window(0,0,LCD_W-1,LCD_H-1);
  130. }

复制代码


源程序:
F410_LCD_PIC_Demo.rar (2.55 MB, 下载次数: 7)
回复

使用道具 举报

该用户从未签到

63

主题

1887

帖子

17

蝴蝶豆

论坛元老

最后登录
2023-2-2
发表于 2021-1-10 00:12:06 | 显示全部楼层
look
回复

使用道具 举报

该用户从未签到

22

主题

1351

帖子

62

蝴蝶豆

论坛元老

最后登录
2021-9-26
发表于 2021-1-10 14:41:44 | 显示全部楼层
学习,学习。
手上有2.4寸arduino屏和某宝上STM32F401CC核心板
想跟着玩玩。

发现arduino屏的针脚与洞洞板不匹配,烦躁。
回复 支持 反对

使用道具 举报

该用户从未签到

22

主题

1351

帖子

62

蝴蝶豆

论坛元老

最后登录
2021-9-26
发表于 2021-1-10 14:42:38 | 显示全部楼层
还有,这屏带触摸的,能否研究一下如何使用上?
回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

999

帖子

0

蝴蝶豆

论坛元老

最后登录
2021-3-31
发表于 2021-1-10 19:09:11 | 显示全部楼层
学习,学习。
回复

使用道具 举报

该用户从未签到

0

主题

189

帖子

6

蝴蝶豆

金牌会员

最后登录
2021-3-3
发表于 2021-1-11 14:40:31 | 显示全部楼层
学习个
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|论坛-意法半导体STM32/STM8技术社区

GMT+8, 2024-3-29 13:32 , Processed in 1.176911 second(s), 38 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表