第七讲 单片机驱动彩色液晶屏 控制RA8889软件:显示文字:Part3.自建字库

单片机驱动TFT彩色液晶屏系列讲座

目录

第一讲 单片机最小系统STM32F103C6T6通过RA8889驱动彩色液晶屏播放视频
第二讲 单片机最小系统STM32F103C6T6控制RA8889驱动彩色液晶屏硬件框架
第三讲 单片机驱动彩色液晶屏 控制RA8889软件:如何初始化
第四讲 单片机驱动彩色液晶屏 控制RA8889软件:绘图
第五讲 单片机驱动彩色液晶屏 控制RA8889软件:显示文字:Part1.内部字库
第六讲 单片机驱动彩色液晶屏 控制RA8889软件:显示文字:Part2.外接字库
第七讲 单片机驱动彩色液晶屏 控制RA8889软件:显示文字:Part3.自建字库
第八讲 单片机驱动彩色液晶屏 控制RA8889软件:显示图片
第九讲 单片机驱动彩色液晶屏 控制RA8889软件:显存操作
第十讲 单片机驱动彩色液晶屏 控制RA8889软件:图像运算
第十一讲 单片机驱动彩色液晶屏 控制RA8889软件:播放avi视频
第十二讲 单片机驱动彩色液晶屏 如何打包bin档
第十三讲单片机驱动彩色液晶屏 bin档的烧录方法

如何通过RA8889 / RA8876来显示文字?
UI界面需求最大的两个功能,第一个是显示图形,第二个是显示文字。文字部分有ASCII和中文,或者是多国语言,下面我们就专门针对RA8889如何显示文字展开介绍。

本章要介绍如何自建中文字库,以及单片机如何控制RA8889进行调用并显示。

本篇要展现的内容比较丰富,篇幅较长,需要多些耐心阅读。

三种文字显示方法的优缺比较:
在这里插入图片描述
通过上图比较,自建字库除了显示速度会慢一些,优势还是很大,设计灵活度也很高,同时还可以节省专用字库芯片的成本,具有一定的经效益,因此值得C友多加参考!

下面开始介绍单片机如何控制RA8889来驱动彩屏显示文字,这里主要是针对显示中文字体进行展开说明,若还有其他国家的字体也可以借鉴该方法进行设计,有兴趣的C友们可留言进行探讨。

一、需求的中文字数不多,采用以下方法
  1. 自建点阵字码表;
  2. 单片机获取字码数据,按点写入显存,同时指定前景、背景及透明色。

框架图:
在这里插入图片描述

调用函数:

void User_Font_Demo(void)
{
    Show_User_Font(25, 32, 350, 180, 0, color65k_red, color65k_green, "菱致电子瑞佑科技");
    Show_User_Font(25, 32, 260, 260, 1, color65k_black, color65k_red, "单片机驱动彩色液晶屏极简方案");
    delay_seconds(3);
}

子函数:

void Show_User_Font(
    unsigned int font_lib_size // 自建字库数组的文字个数
    ,
    unsigned int font_size // 字模大小,比如32*32点阵写32
    ,
    unsigned short x // 显示窗口的x轴坐标
    ,
    unsigned short y // 显示窗口的y轴坐标
    ,
    int Chroma_key // 是否透明:0-不透明 1-透明色
    ,
    unsigned long Foreground_color // 前景色
    ,
    unsigned long Background_color // 背景色
    ,
    const unsigned char *str // 字符串
)
{
    unsigned int i, j = 0;
    unsigned int k, len; // len;字符串的长度
    unsigned char hanziCode[128];
    unsigned char strfont_0, strfont_1, Index_0, Index_1;

    Goto_Pixel_XY(x, y);
    strcpy((char *)hanziCode, str);
    len = strlen(hanziCode) / 2; // 一个中文汉字占两个字节

    for (k = 0; k < len; k++) {
        strfont_0 = *(hanziCode + j); // 字符值
        j++;
        strfont_1 = *(hanziCode + j);
        j++;
        for (i = 0; i < font_lib_size; i++) {
            Index_0 = code_GB_32[i].Index[0]; // 取出字库数组中汉字内码索引值
            Index_1 = code_GB_32[i].Index[1];
            if (strfont_0 == Index_0 && strfont_1 == Index_1) // 比较字符值与汉字内码索引值
            {
                if (Chroma_key == 1)
                    BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_8bit(0, canvas_image_width, x + font_size * k, y, font_size, font_size, Foreground_color, code_GB_32[i].Msk); // 透明色
                if (Chroma_key == 0)
                    BTE_MCU_Write_ColorExpansion_MCU_8bit(0, canvas_image_width, x + font_size * k, y, font_size, font_size, Foreground_color, Background_color, code_GB_32[i].Msk); // 非透明色
                break;
            }
        }
    }
}

上例中BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_8bitBTE_MCU_Write_ColorExpansion_MCU_8bit为瑞佑官方API接口程序,本文暂不缀述。实例显示效果如下图:
在这里插入图片描述
自建汉字每个字皆可单独取模,因此可展现不同字体。

附上自建汉字字模数组,汉字取模软件为横向8点左高位,从左到右,从上到下排列。取模的软件在网上可找到很多,也可以留言和我联络获取。

// ------------------  汉字字模的数据结构定义 ------------------------ //
typedef struct typFNT_GB32                // 汉字字模数据结构
{
       signed char Index[2];              // 汉字内码索引
       char Msk[128];                     // 点阵码数据:32*32/8=128
};

/
// 汉字字模表                                                           //
// Font:32,横向取模左高位,数据排列:从左到右从上到下                       //


struct typFNT_GB32 code_GB_32[] =   // 菱致电子瑞佑科技单片机驱动彩色液晶屏极简方案
{
"菱", 0x00,0x00,0x00,0x00,0x00,0x60,0x06,0x00,
      0x00,0x60,0x06,0x00,0x00,0x60,0x06,0x00,
      0x3F,0xFF,0xFF,0xFC,0x00,0x60,0x06,0x00,
      0x00,0x61,0x06,0x00,0x00,0x41,0x84,0x00,
      0x0F,0xFF,0xFF,0xF0,0x0F,0xFF,0xFF,0xF0,
      0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,
      0x3F,0xFF,0xFF,0xFC,0x3F,0xFF,0xFF,0xFC,
      0x00,0x00,0x00,0x00,0x00,0x60,0x0E,0x00,
      0x00,0xE0,0x07,0x00,0x03,0x88,0x01,0xC0,
      0x07,0x18,0x00,0x70,0x3C,0x30,0x00,0x38,
      0x30,0x7F,0xFF,0x0C,0x01,0xE0,0x03,0x00,
      0x03,0xB0,0x07,0x00,0x0E,0x18,0x0C,0x00,
      0x1C,0x0E,0x38,0x00,0x00,0x03,0xE0,0x00,
      0x00,0x03,0xC0,0x00,0x00,0x1F,0x78,0x00,
      0x01,0xF8,0x0F,0xE0,0x3F,0x80,0x00,0xFE,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"致", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x10,0x00,0x3F,0xFF,0x10,0x00,
      0x3F,0xFF,0x10,0x00,0x03,0x00,0x30,0x00,
      0x02,0x08,0x3F,0xFC,0x06,0x0C,0x30,0x20,
      0x04,0x0C,0x30,0x20,0x0C,0x04,0x20,0x20,
      0x08,0x06,0x20,0x20,0x18,0x1E,0x70,0x20,
      0x3F,0xFF,0x70,0x60,0x10,0xC3,0x50,0x60,
      0x00,0xC1,0x50,0x60,0x00,0xC0,0xD8,0x40,
      0x00,0xC0,0x18,0x40,0x00,0xC0,0x08,0xC0,
      0x00,0xC0,0x0C,0xC0,0x3F,0xFE,0x0D,0x80,
      0x00,0xC0,0x07,0x80,0x00,0xC0,0x07,0x00,
      0x00,0xC0,0x03,0x00,0x00,0xC0,0x07,0x80,
      0x00,0xC0,0x0D,0x80,0x00,0xC7,0x18,0xC0,
      0x00,0xFE,0x30,0x60,0x03,0xF0,0x60,0x30,
      0x3F,0x01,0xC0,0x18,0x30,0x01,0x80,0x0C,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"电", 0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
      0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,
      0x00,0x03,0x00,0x00,0x0F,0xFF,0xFF,0xE0,
      0x1F,0xFF,0xFF,0xE0,0x10,0x03,0x00,0x20,
      0x10,0x03,0x00,0x20,0x10,0x03,0x00,0x20,
      0x10,0x03,0x00,0x20,0x10,0x03,0x00,0x20,
      0x1F,0xFF,0xFF,0xE0,0x1F,0xFF,0xFF,0xE0,
      0x10,0x03,0x00,0x20,0x10,0x03,0x00,0x20,
      0x10,0x03,0x00,0x20,0x10,0x03,0x00,0x20,
      0x10,0x03,0x00,0x20,0x10,0x03,0x00,0x20,
      0x10,0x03,0x00,0x20,0x1F,0xFF,0xFF,0xE0,
      0x07,0xFF,0xFF,0x80,0x00,0x03,0x00,0x06,
      0x00,0x03,0x00,0x06,0x00,0x03,0x00,0x06,
      0x00,0x03,0x00,0x04,0x00,0x03,0x00,0x0C,
      0x00,0x01,0xFF,0xFC,0x00,0x00,0xFF,0xF0,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"子", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x07,0xFF,0xFF,0x80,0x07,0xFF,0xFF,0x80,
      0x00,0x00,0x03,0x80,0x00,0x00,0x06,0x00,
      0x00,0x00,0x1C,0x00,0x00,0x00,0x38,0x00,
      0x00,0x00,0xE0,0x00,0x00,0x03,0x80,0x00,
      0x00,0x07,0x00,0x00,0x00,0x03,0x00,0x00,
      0x00,0x01,0xC0,0x00,0x00,0x00,0xE0,0x00,
      0x3F,0xFF,0xFF,0xFE,0x3F,0xFF,0xFF,0xFE,
      0x00,0x00,0x30,0x00,0x00,0x00,0x18,0x00,
      0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,
      0x00,0x00,0x18,0x00,0x00,0x00,0x08,0x00,
      0x00,0x00,0x08,0x00,0x00,0x00,0x08,0x00,
      0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,
      0x01,0x00,0x18,0x00,0x01,0xC0,0x70,0x00,
      0x00,0xFF,0xE0,0x00,0x00,0x1F,0x80,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"瑞", 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,
      0x00,0x00,0x3F,0x00,0x00,0x07,0xBF,0x7C,
      0x3F,0xF7,0xBF,0x7C,0x7F,0xF7,0xBF,0x7C,
      0x7F,0xFF,0xBF,0x7C,0x7F,0xF7,0xFF,0xFC,
      0x3F,0xF7,0xFF,0xFC,0x0F,0xE7,0xFF,0xFC,
      0x0F,0xCF,0xFF,0xF8,0x0F,0xC0,0x00,0x00,
      0x0F,0xDF,0xFF,0xFC,0x3F,0xFF,0xFF,0xFE,
      0x3F,0xFF,0xFF,0xFE,0x3F,0xFF,0xFF,0xFE,
      0x3F,0xDF,0xFF,0xFC,0x3F,0xC0,0x7E,0x00,
      0x1F,0xCF,0xFF,0xF8,0x0F,0xDF,0xFF,0xFC,
      0x0F,0xDF,0xFF,0xFC,0x0F,0xEF,0xFF,0xFC,
      0x3F,0xF7,0x77,0x7C,0x7F,0xF7,0x77,0x7C,
      0x7F,0xF7,0x77,0x7C,0x7F,0xF7,0x77,0x7C,
      0x7F,0xFF,0x76,0xFC,0x10,0x1F,0x75,0xFC,
      0x00,0x1F,0x75,0xFC,0x00,0x1F,0x75,0xFC,
      0x00,0x1F,0x75,0xFC,0x00,0x00,0x00,0x00,

"佑", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x01,0xF8,0x7F,0x00,0x01,0xF8,0x7F,0x00,
      0x03,0xF8,0x7F,0x00,0x03,0xE0,0x7F,0x00,
      0x03,0xCF,0xFF,0xFE,0x07,0xDF,0xFF,0xFF,
      0x07,0xDF,0xFF,0xFF,0x07,0xDF,0xFF,0xFF,
      0x0F,0xDF,0xFF,0xFF,0x1F,0xCF,0xFF,0xFE,
      0x1F,0xE3,0xFC,0x00,0x3F,0xE3,0xF8,0x00,
      0x3F,0xE7,0xC0,0x00,0x3F,0xEF,0x9F,0xF8,
      0x1F,0xCF,0xBF,0xFE,0x0F,0x9F,0xBF,0xFE,
      0x07,0xBF,0xBF,0xFE,0x07,0xBF,0xBF,0xFE,
      0x07,0xBF,0xBF,0xFE,0x07,0x9F,0x38,0x7E,
      0x07,0xCE,0x78,0x7E,0x07,0xE0,0xF8,0x7E,
      0x07,0xE1,0xF8,0x7E,0x07,0xE1,0xFF,0xFE,
      0x07,0xE1,0xFF,0xFE,0x07,0xE1,0xFF,0xFE,
      0x07,0xE1,0xFF,0xFE,0x07,0xE1,0xFF,0xFE,
      0x07,0xE0,0xFF,0xFC,0x00,0x00,0x00,0x00,

"科", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x1F,0xFE,0x01,0xF0,0x3F,0xFE,0x63,0xF8,
      0x3F,0xFC,0xF9,0xF8,0x3F,0xFD,0xFC,0xF8,
      0x3F,0xFD,0xFE,0x78,0x1F,0xF9,0xFF,0x78,
      0x07,0xF1,0xFF,0x78,0x3F,0xFE,0x3E,0x78,
      0x7F,0xFE,0x0C,0xF8,0x7F,0xFD,0xF1,0xF8,
      0x7F,0xFD,0xF9,0xF8,0x7F,0xFB,0xFE,0xF8,
      0x3F,0x81,0xFE,0x78,0x07,0x31,0xFE,0x78,
      0x0E,0xF8,0x7E,0xF8,0x0E,0xFC,0x1C,0xF8,
      0x1E,0xFE,0x01,0xFC,0x3E,0x7E,0x07,0xFE,
      0x7F,0x7E,0xFF,0xFE,0x7F,0xBC,0xFF,0xFE,
      0x7F,0x89,0xFF,0xFE,0x7F,0xE7,0xFF,0xFE,
      0x3F,0xF7,0xFF,0xF8,0x07,0xF3,0x83,0xF8,
      0x07,0xF0,0x03,0xF8,0x07,0xF0,0x03,0xF8,
      0x07,0xF0,0x03,0xF8,0x07,0xF0,0x03,0xF8,
      0x03,0xE0,0x01,0xF8,0x00,0x00,0x00,0x00,

"技", 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
      0x07,0xC0,0x3F,0x00,0x07,0xE0,0x3F,0x00,
      0x07,0xE0,0x3F,0x00,0x07,0xE0,0x7F,0x80,
      0x0F,0xE7,0xFF,0xFC,0x3F,0xEF,0xFF,0xFE,
      0x7F,0xEF,0xFF,0xFE,0x7F,0xEF,0xFF,0xFE,
      0x7F,0xEF,0xFF,0xFC,0x7F,0xF3,0xFF,0xF8,
      0x1F,0xF0,0x3F,0x00,0x07,0xE1,0xFF,0xF0,
      0x07,0xE7,0xFF,0xF8,0x07,0xF7,0xFF,0xFC,
      0x3F,0xF7,0xFF,0xFC,0x7F,0xF7,0xFF,0xFC,
      0x7F,0xF7,0xF1,0xF8,0x7F,0xF3,0xF1,0xF8,
      0x7F,0xF3,0xFF,0xF8,0x3F,0xE1,0xFF,0xF0,
      0x07,0xE1,0xFF,0xE0,0x07,0xE0,0xFF,0xC0,
      0x07,0xE3,0xFF,0xF0,0x3F,0xCF,0xFF,0xFC,
      0x3F,0xDF,0xFF,0xFE,0x7F,0xDF,0xFF,0xFE,
      0x7F,0xDF,0xF3,0xFE,0x7F,0xDF,0xE0,0xFE,
      0x3F,0xCF,0x80,0x7C,0x00,0x00,0x00,0x00,

"单", 0x00,0x00,0x00,0x00,0x00,0x01,0x38,0x00,
      0x00,0x03,0x3C,0x00,0x00,0x3E,0x38,0x00,
      0x00,0x3E,0x70,0x00,0x00,0x3C,0xE0,0x00,
      0x00,0x1C,0xE0,0x00,0x00,0x1D,0xFC,0x00,
      0x00,0x07,0xFE,0x00,0x00,0x0F,0xCF,0x00,
      0x00,0xB3,0x8F,0x00,0x00,0xC3,0xCF,0x00,
      0x00,0xEF,0xFE,0x00,0x00,0x7F,0xDC,0x00,
      0x00,0x7F,0x9C,0x00,0x00,0x63,0xF8,0x00,
      0x00,0x7F,0xF8,0x00,0x00,0x3F,0xF0,0x00,
      0x00,0x1F,0x9F,0xC0,0x00,0x07,0xFF,0xE0,
      0x00,0x3F,0x80,0x60,0x01,0xFB,0x80,0x00,
      0x0F,0xC3,0x80,0x00,0x0F,0x03,0x80,0x00,
      0x0C,0x03,0x80,0x00,0x00,0x03,0x80,0x00,
      0x00,0x03,0x80,0x00,0x00,0x01,0x80,0x00,
      0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,
      0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,

"片", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0xE0,0x00,0x00,0x00,0x78,0x00,
      0x00,0x00,0x38,0x00,0x00,0x20,0x38,0x00,
      0x00,0x38,0x30,0x00,0x00,0x1C,0x30,0x00,
      0x00,0x1C,0x7C,0x00,0x00,0x1C,0x7E,0x00,
      0x00,0x1B,0xFE,0x00,0x00,0x1F,0xF0,0x00,
      0x00,0x19,0xC0,0x00,0x00,0x1A,0x00,0x00,
      0x00,0x18,0x1F,0x80,0x00,0x19,0xFF,0xC0,
      0x00,0x1F,0xD8,0x00,0x00,0x1E,0x18,0x00,
      0x00,0x18,0x18,0x00,0x00,0x38,0x18,0x00,
      0x00,0x30,0x18,0x00,0x00,0x30,0x18,0x00,
      0x00,0x70,0x18,0x00,0x00,0xE0,0x18,0x00,
      0x00,0xC0,0x18,0x00,0x00,0x40,0x18,0x00,
      0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,
      0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"机", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x30,0x00,0x00,0x00,0x18,0x00,0x00,
      0x00,0x18,0x00,0x00,0x00,0x18,0x06,0x00,
      0x00,0x38,0x0F,0x00,0x00,0x3D,0x1F,0x80,
      0x00,0x3E,0xBF,0x00,0x00,0xFC,0xC7,0x00,
      0x01,0xF0,0xC6,0x00,0x2F,0xF0,0xC6,0x00,
      0x1F,0xB4,0xC6,0x00,0x1F,0x34,0x8E,0x00,
      0x06,0x78,0x8C,0x00,0x00,0x70,0x8C,0x40,
      0x00,0xF1,0x8C,0x20,0x03,0xE1,0x8C,0x30,
      0x07,0xE1,0x8C,0x10,0x07,0xE1,0x8C,0x18,
      0x03,0x61,0x0E,0x1C,0x00,0x63,0x07,0xFE,
      0x00,0x62,0x01,0xF8,0x00,0x60,0x00,0x00,
      0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"驱", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x1E,0x03,0xC0,0x00,0xFF,0x1F,0xC0,
      0x00,0x7F,0x0F,0x80,0x00,0x3F,0x10,0x00,
      0x00,0x0E,0x20,0x00,0x00,0x8E,0x31,0xC0,
      0x00,0x8E,0x30,0xE0,0x01,0x8C,0x30,0xE0,
      0x01,0x9C,0x38,0xE0,0x01,0x9C,0x3E,0xC0,
      0x01,0x9C,0x3F,0xC0,0x01,0xFF,0x23,0xE0,
      0x03,0xFF,0xA3,0xE0,0x03,0xC3,0xA7,0xF0,
      0x01,0x83,0xBF,0x70,0x00,0x33,0x6C,0x30,
      0x03,0xE3,0x60,0x00,0x1F,0xC7,0x60,0x70,
      0x1F,0x87,0x7F,0xF8,0x0E,0x8E,0x3F,0xFC,
      0x08,0x7E,0x18,0x00,0x00,0x1C,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"动", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,
      0x00,0x7E,0x07,0x00,0x00,0x7F,0x07,0x00,
      0x00,0x3F,0x0B,0x00,0x00,0x1E,0x0B,0x00,
      0x00,0x38,0x07,0xC0,0x00,0x60,0x1F,0xE0,
      0x01,0xC7,0x3F,0xE0,0x03,0x3F,0xFE,0x60,
      0x04,0xFE,0x4C,0x60,0x0F,0xFC,0xDC,0x60,
      0x0F,0xFC,0x9C,0x60,0x0F,0xFB,0x98,0xC0,
      0x07,0x73,0x98,0xC0,0x00,0xE7,0xB8,0xC0,
      0x01,0xDF,0xB8,0xC0,0x01,0xFD,0xE8,0xC0,
      0x01,0xF0,0x6D,0x80,0x00,0xE0,0x47,0x80,
      0x00,0x40,0xC7,0x80,0x00,0x00,0x87,0x00,
      0x00,0x01,0x02,0x00,0x00,0x02,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"彩", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,
      0x00,0x07,0x80,0x00,0x00,0x0F,0x84,0x00,
      0x00,0x3F,0x87,0x00,0x00,0x70,0x07,0xC0,
      0x00,0xC7,0xC3,0xC0,0x00,0x7C,0xC3,0xC0,
      0x01,0x99,0xC7,0x80,0x01,0x8B,0x8E,0x00,
      0x01,0xCF,0x1E,0x00,0x00,0xDF,0x9F,0x80,
      0x00,0x7F,0xA1,0x80,0x01,0xFC,0x21,0xC0,
      0x07,0xEC,0x43,0x80,0x1F,0x8E,0x47,0x00,
      0x7F,0x0C,0x8F,0x00,0x7C,0x1D,0x1F,0xC0,
      0x00,0x3E,0x18,0xE0,0x00,0x7C,0x10,0xE0,
      0x03,0xF8,0x00,0xE0,0x07,0xF8,0x01,0xC0,
      0x07,0x98,0x03,0x80,0x00,0x08,0x07,0x00,
      0x00,0x08,0x0E,0x00,0x00,0x08,0x18,0x00,
      0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"色", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x03,0x00,0x00,0x00,0x03,0x80,0x00,
      0x00,0x07,0x80,0x00,0x00,0x0F,0x80,0x00,
      0x00,0x1F,0xE0,0x00,0x00,0x3F,0xF0,0x00,
      0x00,0x38,0xF0,0x00,0x00,0x31,0xC0,0x00,
      0x00,0x23,0x80,0x00,0x00,0x07,0xF8,0x00,
      0x00,0x0F,0xFC,0x00,0x00,0x3F,0x1E,0x00,
      0x00,0xFF,0x9C,0x00,0x00,0xF3,0x98,0x00,
      0x00,0x63,0x38,0x00,0x00,0x67,0xF0,0x00,
      0x00,0x7F,0xF8,0x00,0x00,0xFC,0x00,0x00,
      0x00,0xF0,0x00,0x20,0x00,0xC0,0x00,0x20,
      0x00,0xC0,0x00,0x20,0x00,0xC0,0x00,0x60,
      0x00,0xC0,0x00,0x60,0x00,0x70,0x03,0xF0,
      0x00,0x3F,0xFF,0xF0,0x00,0x0F,0xFF,0xC0,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"液", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x01,0xC0,0x00,0x00,0x03,0xF0,0x00,
      0x00,0x83,0xF0,0x00,0x00,0xC2,0xF0,0x00,
      0x00,0xE3,0x90,0x00,0x00,0x76,0x38,0x00,
      0x00,0x71,0xFC,0x00,0x00,0xFF,0xFC,0x00,
      0x00,0x0F,0xF0,0x00,0x08,0x07,0xE0,0x00,
      0x18,0x01,0xFF,0x00,0x18,0x03,0x9F,0x00,
      0x1E,0x0F,0x3B,0x80,0x0F,0x1E,0x33,0x00,
      0x07,0x2E,0x77,0x00,0x07,0x3E,0xFE,0x00,
      0x07,0x3E,0xDC,0x00,0x06,0x77,0x9C,0x00,
      0x06,0xEF,0xF8,0x00,0x07,0x4C,0x78,0x00,
      0x07,0x0C,0x7C,0x00,0x07,0x0C,0x1F,0x00,
      0x07,0x0C,0x0F,0xE0,0x07,0x0C,0x07,0xF8,
      0x02,0x0C,0x01,0xFC,0x00,0x04,0x00,0x1C,
      0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"晶", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x01,0xF8,0x00,
      0x00,0x07,0xFC,0x00,0x00,0x3F,0x9C,0x00,
      0x00,0x30,0x1C,0x00,0x00,0x18,0x1C,0x00,
      0x00,0x1F,0xD8,0x00,0x00,0x1F,0xD8,0x00,
      0x00,0x1E,0x18,0x00,0x00,0x18,0x18,0x00,
      0x00,0x1F,0xF8,0x00,0x00,0x1F,0xF0,0x00,
      0x00,0x08,0x7F,0x80,0x00,0x00,0x3F,0x80,
      0x00,0x0C,0xF3,0xC0,0x00,0x3E,0xC3,0xC0,
      0x01,0xC6,0xC3,0x80,0x01,0x86,0xFB,0x80,
      0x01,0xFE,0xFF,0x80,0x01,0xF6,0xC3,0x80,
      0x00,0xC6,0xC3,0x80,0x00,0xC6,0xFB,0x80,
      0x00,0xFE,0xFF,0x80,0x00,0xFE,0x43,0x80,
      0x00,0xE6,0x03,0x00,0x00,0x44,0x03,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"屏", 0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,
      0x00,0x01,0xFE,0x00,0x00,0x07,0xFE,0x00,
      0x00,0x0B,0xFE,0x00,0x00,0x1C,0x9C,0x00,
      0x00,0x0C,0x38,0x00,0x00,0x1F,0xF8,0x00,
      0x00,0x1F,0xFC,0x00,0x00,0x3F,0x08,0x00,
      0x00,0x34,0x7E,0x00,0x00,0x37,0x8C,0x00,
      0x00,0x67,0x18,0x00,0x00,0x63,0x7C,0x00,
      0x00,0xC3,0xFC,0x00,0x00,0xDF,0xFC,0x00,
      0x01,0x87,0xCC,0x00,0x01,0x87,0x0C,0xC0,
      0x01,0x06,0xFF,0xE0,0x03,0x0F,0xFD,0xF0,
      0x07,0x3F,0x0C,0x00,0x06,0xFE,0x0C,0x00,
      0x0E,0xF6,0x0C,0x00,0x0C,0x06,0x0C,0x00,
      0x18,0x0E,0x0C,0x00,0x30,0x0E,0x0C,0x00,
      0x60,0x0C,0x0C,0x00,0x00,0x08,0x0C,0x00,
      0x00,0x00,0x0C,0x00,0x00,0x00,0x0C,0x00,
      0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,

"极", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
      0x00,0x38,0x00,0x00,0x00,0x1C,0x06,0x00,
      0x00,0x1C,0x0F,0x00,0x00,0x1C,0x3D,0x80,
      0x00,0x3E,0x79,0x80,0x00,0xFE,0xF1,0x80,
      0x01,0xFD,0xF9,0x80,0x27,0xF8,0xF3,0x00,
      0x1F,0xF9,0x73,0x00,0x1F,0xBA,0x67,0x00,
      0x0F,0x3C,0xE3,0x80,0x06,0x38,0xC3,0x80,
      0x00,0x39,0xC0,0xC0,0x00,0x71,0xC0,0xC0,
      0x00,0xFF,0xF0,0xC0,0x01,0xF3,0xFD,0xC0,
      0x03,0xE3,0x1F,0x80,0x03,0xE7,0x0F,0xC0,
      0x01,0xE6,0x0F,0xE0,0x01,0x37,0x3F,0xF0,
      0x00,0x34,0xF8,0xF8,0x00,0x34,0x20,0x3C,
      0x00,0x10,0x00,0x1C,0x00,0x10,0x00,0x04,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"简", 0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,
      0x00,0x00,0x0E,0x00,0x00,0x10,0x0E,0x00,
      0x00,0x18,0x1E,0x00,0x00,0x3C,0xBF,0xC0,
      0x00,0x79,0xBF,0xC0,0x00,0xFF,0x3F,0x80,
      0x01,0xFF,0x16,0x00,0x01,0xF6,0x1C,0x00,
      0x01,0xC0,0x7E,0x00,0x00,0x01,0xFF,0x00,
      0x00,0x07,0xCF,0x00,0x00,0x1C,0x07,0x80,
      0x00,0x18,0x07,0x80,0x00,0x3B,0xC3,0x80,
      0x00,0xA3,0xE3,0x80,0x00,0xCC,0x63,0x80,
      0x00,0xCC,0x63,0x80,0x00,0x8F,0xE3,0x80,
      0x00,0x4F,0x63,0x80,0x00,0x4C,0x67,0x80,
      0x00,0x8F,0xE7,0x80,0x00,0x8F,0xC7,0x80,
      0x00,0x86,0xC7,0x80,0x01,0x80,0x47,0x80,
      0x01,0x80,0x3F,0x80,0x00,0x80,0x1F,0x80,
      0x00,0x00,0x07,0x80,0x00,0x00,0x03,0x00,
      0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,

"方", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x03,0x80,0x00,0x00,0x03,0xE0,0x00,
      0x00,0x01,0xE0,0x00,0x00,0x00,0xF0,0x00,
      0x00,0x01,0xF0,0x00,0x00,0x03,0x80,0x00,
      0x00,0x1C,0x3F,0xE0,0x00,0x0F,0xE3,0xF0,
      0x00,0xFF,0xCE,0x00,0x0F,0xF8,0xF0,0x00,
      0x0F,0xE0,0xE0,0x00,0x0F,0x81,0xF8,0x00,
      0x06,0x01,0xFE,0x00,0x00,0x03,0x87,0x00,
      0x00,0x07,0x07,0x00,0x00,0x0E,0x07,0x00,
      0x00,0x1C,0x0E,0x00,0x00,0x3A,0x0E,0x00,
      0x00,0x72,0x1C,0x00,0x00,0xE2,0x38,0x00,
      0x01,0x83,0x78,0x00,0x01,0x03,0xF0,0x00,
      0x00,0x01,0xE0,0x00,0x00,0x01,0xC0,0x00,
      0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

"案", 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0xE0,0x00,0x00,0x00,0x60,0x00,
      0x00,0x00,0x7C,0x00,0x00,0x00,0xCF,0x00,
      0x00,0x09,0x8F,0x00,0x00,0x0F,0x9E,0x00,
      0x00,0x1F,0xBC,0x00,0x00,0x3E,0xF8,0x00,
      0x00,0x1D,0x7B,0xE0,0x00,0x19,0xFF,0xF0,
      0x00,0x0F,0x70,0x00,0x01,0xFE,0x70,0x00,
      0x0F,0xCF,0xE0,0x00,0x1F,0x0F,0xF8,0x00,
      0x00,0x03,0xFE,0x00,0x00,0x0F,0x8E,0x00,
      0x00,0xFF,0xE3,0x00,0x00,0x00,0xFF,0x00,
      0x00,0x3F,0xE0,0x00,0x00,0x1C,0x60,0x00,
      0x00,0x00,0x60,0x00,0x00,0x02,0x67,0x00,
      0x00,0x3C,0x63,0x80,0x00,0x38,0xE1,0x80,
      0x00,0x31,0xE0,0x80,0x00,0x20,0xC0,0x00,
      0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
二、需求全套中文,字数多必然需要更多存储空间,那么可以存放到FLASH中。

这里所讲的FLASH是与RA8889 / RA8876连接的,一般是用来存放UI所需的图资,也可以将字库存放于此,这样不需要增加成本,但可节省掉外接字库芯片的成本!

框架图:
在这里插入图片描述

自建字库不限套数,单套占用容量不大,比如24x24点是576KB。这里提供的算法是通过RA8889 / RA8876的DMA(Direct Memory Access)功能获取到字符数据,再通过BTE(Block Transfer Engine)功能将文字显示出来。经过优化,目前显示速度还算不错,参考下方展示视频:

自建字库显示速度(分辨率800x480)

调用代码范例:

   // 演示自建字库调用
    BTE_Solid_Fill(display_address, canvas_image_width, 0, 0, 0x01, LCD_width, LCD_height); // 缓存显示区域:填充底色0x01;display_address此处自定义为canvas_image_width*LCD_height*24/8
    SPI_NOR_initial_DMA(0, Font_BUS, Font_CS, 1, 0);    //FLASH初始化
    User_Def_Font_Initial();    //显示自定义文字初始化

    Font_Size_ChromaKey_ForeColor_BackColor(24, 1, color256_red, color256_white);    //字体参数设定(最多256色)
    Show_User_Def_String("自建汉字库:宋体16x16演示", songti16, 16, 2, 50, 20);    //显示字符串
    Show_User_Def_String("自建汉字库:楷体16x16演示", kaiti16, 16, 2, 50, 45);    //显示字符串
    Show_User_Def_String("自建汉字库:黑体16x16演示", heiti16, 16, 2, 50, 70);    //显示字符串

    Font_Size_ChromaKey_ForeColor_BackColor(24, 1, color256_blue, color256_white);    //字体参数设定(最多256色)
    Show_User_Def_String("自建汉字库:宋体24x24演示", songti24, 24, 2, 50, 100);    //显示字符串
    Show_User_Def_String("自建汉字库:楷体24x24演示", kaiti24, 24, 2, 50, 125);    //显示字符串
    Show_User_Def_String("自建汉字库:黑体24x24演示", heiti24, 24, 2, 50, 150);    //显示字符串

    Font_Size_ChromaKey_ForeColor_BackColor(32, 0, color256_yellow, color256_black);    //字体参数设定(最多256色)
    Show_User_Def_String("自建汉字库:宋体32x32演示", songti32, 32, 0, 50, 200);    //显示字符串
    Show_User_Def_String("自建汉字库:楷体32x32演示", kaiti32, 32, 0, 50, 240);    //显示字符串
    Show_User_Def_String("自建汉字库:黑体32x32演示", heiti32, 32, 0, 50, 280);    //显示字符串

	// 图层S0色深恢复初始化状态
	#if defined(MCU_8bit_ColorDepth_8bpp)
		BTE_S0_Color_8bpp();
	#endif
	#if defined(MCU_8bit_ColorDepth_16bpp) || defined(MCU_16bit_ColorDepth_16bpp)
		BTE_S0_Color_16bpp();
	#endif
	#if defined(MCU_8bit_ColorDepth_24bpp) || defined(MCU_16bit_ColorDepth_24bpp_Mode_1) || defined(MCU_16bit_ColorDepth_24bpp_Mode_2)
		BTE_S0_Color_24bpp();
	#endif

    BTE_Memory_Copy_Chroma_key(display_address, canvas_image_width, 0, 0, 0, canvas_image_width, 0, 0, 0x01, LCD_width, LCD_height); // 缓存写好的文字搬移到显示层,剔除底色0x01

上方代码显示实例:
在这里插入图片描述

RA8889内建128Mb SDRAM作为显存,显存是自由定义的,这里我们设定为画布宽度(canvas_image_width)为800,测试的屏宽(LCD_width)为800,屏高(LCD_height)为480,将显存规划为主显示层、缓冲层S0、缓冲层S1…如下图示:
在这里插入图片描述
实际操作分为三步:

  1. DMA(线性):RA8889寻址获取字符数据并通过DMA方式写入缓存S1;
  2. 转置:MCU对缓存S1的数据转置后写入缓存S0,同时给文字加上前景、背景色或者透明色;
  3. BTE剔除底色:RA8889内建BTE功能,可将底色剔除后再复制到主显示层,因此可以形成文字的透明效果。

附上算法程序供参考:

/***************************************************************************************
 * @file	RA8889_Show_User_Def_FontLib_bitPic.c
 * @author	Weran
 * @version	3.0
 * @date	2023/08/16
 * @brief  	显示用户自定义字库或者单色位图,宽度为8的倍数,字形长宽相等,位图不限高度
 * @copyright www.lcdvision.com.cn
 ****************************************************************************************/
#include "RA8889.h"
#include "RA8889_MCU_IF.h"
#include "RA8889_API.h"
#include "delay.h"
#include "RA8889_Show_User_Def_FontLib_bitPic.h"
#include "string.h"

/*****************************************
// 自建汉字库初始化
******************************************/
void User_Def_Font_Initial(void)
{
    SPI_Clock_Period(2);
    Select_SFI_Single_Mode_Dummy_8T_0Bh();
    Enable_SFlash_SPI();

    #ifdef Over_128Mb // FLASH大小超过128Mb,切换为32位寻址
        switch_24bits_to_32bits(Font_BUS, Font_CS);
        Select_SFI_32bit_Address();
    #else
        Select_SFI_24bit_Address();
    #endif

    switch (Font_CS) {
        case 0:
            Select_SFI_0();
            break;
        case 1:
            Select_SFI_1();
            break;
        case 2:
            Select_SFI_2();
            break;
        case 3:
            Select_SFI_3();
            break;
    }

    Select_SFI_DMA_Mode();
    SFI_DMA_Destination_Start_Address(cache_address);

    BTE_S0_Memory_Start_Address(cache_address); // 缓存图层
    BTE_S0_Image_Width(main_image_width);
    BTE_S0_Color_8bpp(); // 缓存色深固定8bit,不可变更

    BTE_Destination_Memory_Start_Address(display_address); // 显示到目的图层
    BTE_Destination_Image_Width(main_image_width);

    // 目的窗口色深
    #if defined(MCU_8bit_ColorDepth_8bpp)
        BTE_Destination_Color_8bpp();
    #endif
    #if defined(MCU_8bit_ColorDepth_16bpp) || defined(MCU_16bit_ColorDepth_16bpp)
        BTE_Destination_Color_16bpp();
    #endif
    #if defined(MCU_8bit_ColorDepth_24bpp) || defined(MCU_16bit_ColorDepth_24bpp_Mode_1) || defined(MCU_16bit_ColorDepth_24bpp_Mode_2)
        BTE_Destination_Color_24bpp();
    #endif

    BTE_Window_Size(8, 1); // 每次延展的区块大小:8x1
    BTE_ROP_Code(15);
}

/*****************************************
// 字体显示效果设定函数
// Font_Size:字型大小
// ChromaKey:0-不透明;1-透明
// Foreground_color:前景色,最多256色
// Foreground_color:背景色,最多256色
******************************************/
void Font_Size_ChromaKey_ForeColor_BackColor(unsigned short Font_Size, unsigned char ChromaKey, unsigned char Foreground_color, unsigned char Background_color)
{
    SFI_DMA_Transfer_Number(Font_Size * Font_Size / 8); // DMA单个汉字字节数

    Foreground_color_256(Foreground_color);

    if (ChromaKey == 1 && Foreground_color == Background_color)
        Background_color_256(Background_color >> 1); // 当选择透明色时前景色与背景色不能一样,移1位区别
    else
        Background_color_256(Background_color);

    if (ChromaKey == 0)
        BTE_Operation_Code(14); // 背景非透明
    else if (ChromaKey == 1)
        BTE_Operation_Code(15); // 背景透明
}

/*****************************************************
// 显示字符串函数
// str:字符串
// Font_Lib_Offset:汉字库在FLASH中地址偏移,宏定义预设
// Font_Size:字型大小
// Font_Gap:字符间距
// x & y:字符串显示坐标
******************************************************/
void Show_User_Def_String(char *str, unsigned int Font_Lib_Offset, unsigned short Font_Size, unsigned char Font_Gap, unsigned short x, unsigned short y)
{
    unsigned char i, len;
    unsigned short hanziIndex;
    const char hanziCode[200];

    strcpy((char *)hanziCode, str);
    len = strlen(&*hanziCode) / 2;

    for (i = 0; i < len; i++) {
        hanziIndex = 94 * (hanziCode[2 * i] - 0xA1) + (hanziCode[2 * i + 1] - 0xA1); // 汉字区码、位码均起始0xA1
        Show_User_Def_Font(hanziIndex, Font_Lib_Offset, Font_Size, x + Font_Size * i + Font_Gap * (i - 1), y);
    }
}

/**********************************************************
// 显示自定义汉字函数
// 注意:字宽必须为8的倍数
// hanziIndex:汉字在国标码中的位置
// Font_Lib_Offset:汉字库在FLASH中地址偏移,宏定义预设
// Font_Size:字型大小
// x & y:字符显示坐标
**********************************************************/
void Show_User_Def_Font(unsigned short hanziIndex, unsigned int Font_Lib_Offset, unsigned short Font_Size, unsigned short x, unsigned short y)
{
    unsigned char i, j;
    unsigned short Width_Byte = Font_Size / 8; // 宽度按字节数
    unsigned short Font_Byte  = 0;             // 单个字体字节计数

    Memory_Linear_Mode(); // 线性模式
    SFI_DMA_Source_Start_Address(Font_Size * Font_Size / 8 * hanziIndex + Font_Lib_Offset);
    Start_SFI_DMA();
    Check_Busy_SFI_DMA();
    Memory_XY_Mode(); // 区块模式

    /*在8bpp模式下先进行转置并延展,再上色*/
    for (i = 0; i < Font_Size; i++) // 字高,每次处理1bit=1点
    {
        for (j = 0; j < Width_Byte; j++) // 字宽
        {
            BTE_S0_Window_Start_XY(Font_Byte++, 0);            // 每次处理1byte=8点
            BTE_Destination_Window_Start_XY(x + 8 * j, y + i); // 转置+延展
            BTE_Enable();
            Check_BTE_Busy();
        }
    }
}

/*****************************************
// 单色位图显示初始化
// Pic_Width:图片宽度
// Pic_Height:图片高度
// ChromaKey:0-不透明;1-透明
// Foreground_color:前景色,最多256色
// Foreground_color:背景色,最多256色
******************************************/
void Bit_Picture_Initial(unsigned short Pic_Width, unsigned short Pic_Height, unsigned char ChromaKey, unsigned char Foreground_color, unsigned char Background_color)
{

    SPI_Clock_Period(2);
    Select_SFI_Single_Mode_Dummy_8T_0Bh();
    Enable_SFlash_SPI();

    #ifdef Over_128Mb // FLASH大小超过128Mb,切换为32位寻址
        switch_24bits_to_32bits(Font_BUS, Font_CS);
        Select_SFI_32bit_Address();
    #else
        Select_SFI_24bit_Address();
    #endif

    switch (Font_CS) {
        case 0:
            Select_SFI_0();
            break;
        case 1:
            Select_SFI_1();
            break;
        case 2:
            Select_SFI_2();
            break;
        case 3:
            Select_SFI_3();
            break;
    }

    Select_SFI_DMA_Mode();
    SFI_DMA_Destination_Start_Address(cache_address);

    BTE_S0_Memory_Start_Address(cache_address); // 缓存图层
    BTE_S0_Image_Width(main_image_width);
    BTE_S0_Color_8bpp(); // 缓存色深固定8bit,不可变更

    BTE_Destination_Memory_Start_Address(display_address); // 显示到目的图层
    BTE_Destination_Image_Width(main_image_width);

    // 目的窗口色深
    #if defined(MCU_8bit_ColorDepth_8bpp)
        BTE_Destination_Color_8bpp();
    #endif
    #if defined(MCU_8bit_ColorDepth_16bpp) || defined(MCU_16bit_ColorDepth_16bpp)
        BTE_Destination_Color_16bpp();
    #endif
    #if defined(MCU_8bit_ColorDepth_24bpp) || defined(MCU_16bit_ColorDepth_24bpp_Mode_1) || defined(MCU_16bit_ColorDepth_24bpp_Mode_2)
        BTE_Destination_Color_24bpp();
    #endif

    BTE_Window_Size(8, 1);                               // 每次延展的区块大小:8x1
    SFI_DMA_Transfer_Number(Pic_Width * Pic_Height / 8); // DMA单张图片字节字节数

    Foreground_color_256(Foreground_color);

    if (ChromaKey == 1 && Foreground_color == Background_color)
        Background_color_256(Background_color >> 1); // 当选择透明色时前景色与背景色不能一样,移1位区别
    else
        Background_color_256(Background_color);

    BTE_ROP_Code(15);
    if (ChromaKey == 0)
        BTE_Operation_Code(14); // 背景非透明
    else if (ChromaKey == 1)
        BTE_Operation_Code(15); // 背景透明
}

/**********************************************************
// 显示单色位图函数
// 注意:图片宽度必须为8的倍数
// Pic_Offset:图片在FLASH中地址偏移
// Pic_Width:图片宽度(必须为8的倍数)
// Pic_Height:图片高度
// x & y:图片显示坐标
**********************************************************/
void Show_Bit_Picture(unsigned int Pic_Offset, unsigned short Pic_Width, unsigned short Pic_Height, unsigned short x, unsigned short y)
{
    unsigned char i, j;
    unsigned short Pic_Width_Byte = Pic_Width / 8; // 宽度按字节数
    unsigned short Pic_Byte       = 0;             // 单张图片字节计数

    Memory_Linear_Mode(); // 线性模式
    SFI_DMA_Source_Start_Address(Pic_Offset);
    Start_SFI_DMA();
    Check_Busy_SFI_DMA();
    Memory_XY_Mode(); // 区块模式

    /*在8bpp模式下先进行转置并延展,再上色*/
    for (i = 0; i < Pic_Height; i++) // 图片高,每次处理1bit=1点
    {
        for (j = 0; j < Pic_Width_Byte; j++) // 图片宽度,按字节数
        {
            BTE_S0_Window_Start_XY(Pic_Byte++, 0);             // 每次处理1byte=8点
            BTE_Destination_Window_Start_XY(x + 8 * j, y + i); // 转置+延展
            BTE_Enable();
            Check_BTE_Busy();
        }
    }
}

函数声明及宏定义:

/****************************************************************************************
  * @file		RA8889_Show_User_Def_FontLib_bitPic.h
  * @author		Weran
  * @version	3.0
  * @date		2023/08/16
  * @brief  	显示用户自定义字库或者单色位图,宽度为8的倍数,字形长宽相等,位图不限高度
  * @copyright www.lcdvision.com.cn
*****************************************************************************************/
#ifndef __RA8889_SHOW_USER_DEF_FONTLIB_BITPIC_H
#define __RA8889_SHOW_USER_DEF_FONTLIB_BITPIC_H
	
#include "UserDef.h"

#define display_address				canvas_image_width*LCD_height*24/8		//延展后目标显示地址
#define	cache_address				canvas_image_width*LCD_height*24/8*2	//缓存地址 (8bpp),宽x高满足单字容量即可

#define Font_BUS	1					//自建字库总线地址
#define Font_CS		2					//自建字库片选地址
//#define Over_128Mb					//FLASH容量超过128Mb

/*字库可以多套合并,套数不限,但字宽必须为8的倍数,bin档可使用PackagingTool等软件合并*/
#define heiti16   0x00000000			//黑体16x16起始地址
#define heiti24   0x0003FE40			//黑体24x24起始地址
#define heiti32   0x000CFA50			//黑体32x32起始地址
#define songti16   0x001CF350			//宋体16x16起始地址
#define songti24   0x0020F190			//宋体24x24起始地址
#define songti32   0x0029EDA0			//宋体32x32起始地址
#define kaiti16   0x0039E6A0			//楷体16x16起始地址
#define kaiti24   0x003DE4E0			//楷体24x24起始地址
#define kaiti32   0x0046E0F0			//楷体32x32起始地址
#define pic		0x0056D9F0					//范例图片起始地址
#define bit_pic		0x00BE35F0			//范例单色位图起始地址,数字0~9


void User_Def_Font_Initial(void);
void Font_Size_ChromaKey_ForeColor_BackColor(unsigned short Font_Size,unsigned char ChromaKey,unsigned char Foreground_color,unsigned char Background_color);
void Show_User_Def_String(char *str,unsigned int Font_Lib_Offset,unsigned short Font_Size,unsigned char Font_Gap,unsigned short x,unsigned short y);
void Show_User_Def_Font(unsigned short hanziIndex, unsigned int Font_Lib_Offset, unsigned short Font_Size, unsigned short x, unsigned short y);

void Bit_Picture_Initial(unsigned short Pic_Width, unsigned short Pic_Height, unsigned char ChromaKey,unsigned char Foreground_color,unsigned char Background_color);
void Show_Bit_Picture(unsigned int Pic_Offset, unsigned short Pic_Width, unsigned short Pic_Height, unsigned short x, unsigned short y);

#endif /*__RA8889_SHOW_USER_DEF_FONTLIB_BITPIC_H*/

自建字库的大小理论上不限,有些用户想要使用矢量字库,那么只需要多做几套各种尺寸的字库一起打包即可,不过点阵越大,容量需求也是指数级增加。

能读到这里不容易,为了您的耐心,我再奉献一个彩蛋!

该功能也适合做数字表,先做好单色(1bit)点阵图片,可以使用Windows自带的“画图”另存即可。图片如下 :
在这里插入图片描述
图片只要确保宽度为8的倍数即可,高度不限,打包好烧写进FLASH之后再进行调用。操作方式与显示文字的方式类似,通过上面提供的函数Show_Bit_Picture进行调用。

显示数字表范例:

/*该函数演示用户自定义位图的调用,位图宽度必须为8的倍数*/
void Show_Bit_Pic_Demo(void)
{
    unsigned short n1, n2, n3, num = 0;

    // 背景图显示,FLASH≦128Mb
    #ifndef Over_128Mb
        SPI_NOR_initial_DMA(0, Font_BUS, Font_CS, 1, 0);
    #if defined(MCU_8bit_ColorDepth_8bpp)
        DMA_24bit(2, 0, 0, LCD_width, LCD_height, 800, pic); // 读取FLASH图片,8bit
    #endif
    #if defined(MCU_8bit_ColorDepth_16bpp) || defined(MCU_16bit_ColorDepth_16bpp)
        DMA_24bit(2, 0, 0, LCD_width, LCD_height, 800, pic + 384000); // 读取FLASH图片,16bit
    #endif
    #if defined(MCU_8bit_ColorDepth_24bpp) || defined(MCU_16bit_ColorDepth_24bpp_Mode_1) || defined(MCU_16bit_ColorDepth_24bpp_Mode_2)
        DMA_24bit(2, 0, 0, LCD_width, LCD_height, 800, pic + 1152000); // 读取FLASH图片,24bit
    #endif
    #endif /*Not Over_128Mb*/

    // 背景图显示,FLASH>128Mb
    #ifdef Over_128Mb
        SPI_NOR_initial_DMA(0, Font_BUS, Font_CS, 1, 1);
    #if defined(MCU_8bit_ColorDepth_8bpp)
        DMA_32bit(2, 0, 0, LCD_width, LCD_height, 800, pic); // 读取FLASH图片,8bit
    #endi #if defined(MCU_8bit_ColorDepth_16bpp) || defined(MCU_16bit_ColorDepth_16bpp)
        DMA_32bit(2, 0, 0, LCD_width, LCD_height, 800, pic + 384000); // 读取FLASH图片,16bit
    #endif
    #if defined(MCU_8bit_ColorDepth_24bpp) || defined(MCU_16bit_ColorDepth_24bpp_Mode_1) || defined(MCU_16bit_ColorDepth_24bpp_Mode_2)
        DMA_32bit(2, 0, 0, LCD_width, LCD_height, 800, pic + 1152000); // 读取FLASH图片,24bit
    #endif
    #endif /*Over_128Mb*/

    // 当前显示画面数字表显示区(100,100)之240x120区块备份到延展后显示目标图层(0,0)(0,120)两份
    BTE_Memory_Copy(0, canvas_image_width, 100, 100, 0, canvas_image_width, 0, 0, display_address, canvas_image_width, 0, 0, 12, 240, 120);
    BTE_Memory_Copy(0, canvas_image_width, 100, 100, 0, canvas_image_width, 0, 0, display_address, canvas_image_width, 0, 120, 12, 240, 120);

    for (num = 0; num < 198; num++) {
        Bit_Picture_Initial(80, 120, 0, color256_white, 0x0);
        n1 = num / 100;
        Show_Bit_Picture(bit_pic + BINARY_INFO[n1].start_addr, 80, 120, 0, 240); // 显示百位0  延展目标层(0,240)
        n2 = (num / 10) % 10;
        Show_Bit_Picture(bit_pic + BINARY_INFO[n2].start_addr, 80, 120, 80, 240); // 显示十位0
        n3 = num % 10;
        Show_Bit_Picture(bit_pic + BINARY_INFO[n3].start_addr, 80, 120, 160, 240); // 显示个位0

    // 图层S0色深恢复初始化状态
    #if defined(MCU_8bit_ColorDepth_8bpp)
            BTE_S0_Color_8bpp();
    #endif
    #if defined(MCU_8bit_ColorDepth_16bpp) || defined(MCU_16bit_ColorDepth_16bpp)
            BTE_S0_Color_16bpp();
    #endif
    #if defined(MCU_8bit_ColorDepth_24bpp) || defined(MCU_16bit_ColorDepth_24bpp_Mode_1) || defined(MCU_16bit_ColorDepth_24bpp_Mode_2)
            BTE_S0_Color_24bpp();
    #endif

        // 备份图(0,120)先复制到(0,0)
        BTE_Memory_Copy(display_address, canvas_image_width, 0, 120, 0, canvas_image_width, 0, 0, display_address, canvas_image_width, 0, 0, 12, 240, 120);
        // 延展图(0,240)剔除底色0x0后再叠加到(0,0)
        BTE_Memory_Copy_Chroma_key(display_address, canvas_image_width, 0, 240, display_address, canvas_image_width, 0, 0, 0x0, 240, 120);
        // 处理好的图(0,0)复制到主显示画面(100,100)
        BTE_Memory_Copy(display_address, canvas_image_width, 0, 0, 0, canvas_image_width, 0, 0, 0, canvas_image_width, 100, 100, 12, 240, 120);

        delay_ms(10);
    }
}

显示效果如下:

自建数字表显示效果演示

看完了有没有收获?满满干货全部奉献,期待您的点赞、分享、留言!!!

关注我,了解更多更好用的的液晶屏驱动方法!

第七讲 THE END

了解更多信息:http://www.lcdvision.com.cn

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/316163.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【重明】机器视觉QT/C++实现工业相机二次开发框架

工业相机二次开发是机器视觉行业必不可少的技能之一。 而如何实现一个框架&#xff0c;能够兼容所有工业相机二次开发&#xff0c;从而支持多种类型的工业相机&#xff0c;就是机器视觉行业的进阶技能了。 重明工业相机二次开发项目就是在实现相机二开框架的基础上&#xff0c…

Java面试汇总——redis篇

1、什么是缓存穿透 ? 怎么解决 ? 缓存穿透是指客户端请求的数据在缓存中和数据库中都不存在&#xff0c;这样缓存就形同虚设&#xff08;只有数据库查到了&#xff0c;才会让redis缓存&#xff0c;但现在的问题是查不到&#xff09;&#xff0c;会频繁的去访问数据库。 解决…

6. 逻辑删除

逻辑删除对应的是物理删除&#xff0c;分别介绍一下这两个概念&#xff1a; 物理删除 &#xff1a;指的是真正的删除&#xff0c;即&#xff1a;当执行删除操作时&#xff0c;将数据表中的数据进行删除&#xff0c;之后将无法再查询到该数据逻辑删除 &#xff1a;并不是真正意…

whistle代理+mock轻松解决“页面端“测试接口没数据难题

0、whistle是什么&#xff1f;怎么用&#xff1f; 自行百度&#xff0c;此处不再赘述&#xff01; 1、示例演示&#xff08;交易订单测试&#xff09; 背景和痛点最近在测试一个小需求&#xff0c;需要涉及订单侧服务商品库侧服务库存侧服务财务侧线下交易服务。痛点主要在订…

淘宝商家实现批量上货API接口调用接入说明(淘宝开放平台免申请接入)

API接入详细步骤&#xff1a; 第一步&#xff1a;在淘宝开放平台中选择接口塡写应用申报递交给我司&#xff0c;确认接口是否都有。 第二步&#xff1a;确认接口都有&#xff0c;需交1000元进行测试&#xff0c;可以测试三天&#xff0c;测试数据符合淘宝开放平台接口参数说明&…

【python】09.面向对象进阶

面向对象进阶 在前面的章节我们已经了解了面向对象的入门知识&#xff0c;知道了如何定义类&#xff0c;如何创建对象以及如何给对象发消息。为了能够更好的使用面向对象编程思想进行程序开发&#xff0c;我们还需要对Python中的面向对象编程进行更为深入的了解。 property装…

轴组【CAN】

如果有126个轴&#xff0c;你程序里挨个添加轴很麻烦。 可以用轴组批量添加。【数组】 CAN驱动器 0x164 就是下个驱动器 p_CAN主站地址:ADR(IoConfig_Globals.CANopen_Manager_SoftMotion);p_CAN从站地址1:ADR(IoConfig_Globals.DMA882_CAN);p_CAN从站地址2:ADR(IoConfig_Gl…

超维空间M1无人机使用说明书——61、ROS无人机物体识别与精准投放

引言&#xff1a;基于空中物流的项目背景。我们提供了使用基于诗句的物体识别和精准投放、降落。实现原理如下&#xff1a; 1、在ROS下使用机载电脑实现物体识别 2、记载电脑根据反馈的位置发布运动控制指令 3、PX4解析机载电脑发布的命令&#xff0c;作出运动控制 4、设置…

PCL 使用克拉默法则进行四点定球(C++详细过程版)

目录 一、算法原理二、代码实现三、计算结果本文由CSDN点云侠原创,PCL 使用克拉默法则进行四点定球(C++详细过程版),爬虫自重。如果你不是在点云侠的博客中看到该文章,那么此处便是不要脸的爬虫与GPT生成的文章。 一、算法原理 已知空间内不共面的四个点,设其坐标为 A (…

【Maven】003-基于 IDEA 创建 Maven 工程

【Maven】003-基于 IDEA 创建 Maven 工程 文章目录 【Maven】003-基于 IDEA 创建 Maven 工程一、关于 Maven 工程的 GAVP1、GAVP 简介2、GAV 坐标规范3、Packaging 定义规则 二、基于 IDEA 创建 Maven 工程1、创建 Maven 项目2、创建结果3、项目结构说明 一、关于 Maven 工程的…

特征工程-特征处理(一)

特征处理-&#xff08;离散型特征处理&#xff09; 完成特征理解和特征清洗之后&#xff0c;我们要进行特征工程中最为重要和复杂的一步了——特征处理 离散型特征处理 离散型特征通常为非连续值或以字符串形式存在的特征&#xff0c;离散型特征通常来讲是不能直接喂入模型中…

HandlerInterceptor拦截器 postHandle执行addHeader无效,postHandle执行setStatus无效的解决方案

问题描述 想在postHandle方法里执行addHeader方法来补充一些Header信息&#xff08;如分页信息&#xff09;&#xff0c;但是最后执行却未如期显示 拦截器源码 import com.zhangziwa.practisesvr.utils.response.ResponseContext; import jakarta.servlet.http.HttpServletR…

必看!2023年机器人领域十大事件!

原创 | 文 BFT机器人 2023年&#xff0c;机器人产业快速发展&#xff0c;成就了机器人领域的一个又一个里程碑。机器人行业涌现了许多令人瞩目的事件&#xff0c;实现了重大突破&#xff0c;展示了机器人技术在各个领域的广泛应用和革命性变革。 本文将对2023年机器人领域的十…

【MATLAB】REMD_LSTM神经网络时序预测算法

有意向获取代码&#xff0c;请转文末观看代码获取方式~也可转原文链接获取~ 1 基本定义 REMD-LSTM神经网络时序预测算法是一种结合了REMD&#xff08;Reservoir Enhanced Multi-scale Deep Learning&#xff09;算法和长短期记忆神经网络&#xff08;LSTM&#xff09;的时间序…

gem5学习(12):理解gem5 统计信息和输出——Understanding gem5 statistics and output

目录 一、config.ini 二、config.json 三、stats.txt 官方教程&#xff1a;gem5: Understanding gem5 statistics and output 在运行 gem5 之后&#xff0c;除了仿真脚本打印的仿真信息外&#xff0c;还会在根目录中名为 m5out 的目录中生成三个文件&#xff1a; config.i…

企业网络两层和三层架构部署有何差异

知识改变命运&#xff0c;技术就是要分享&#xff0c;有问题随时联系&#xff0c;免费答疑&#xff0c;欢迎联系&#xff01; 厦门微思网络​​​​​​ https://www.xmws.cn华为认证\华为HCIA-Datacom\华为HCIP-Datacom\华为HCIE-Datacom Linux\RHCE\RHCE 9.0\RHCA\ Oracle OC…

如何用mixlab-nodes实现LOGO生成的应用DEMO?#这就是生产力

ComfyUI的工作流&#xff0c;可以把一件需要重复的事情变成一个流水线&#xff0c;自动完成&#xff0c;再加上高度可自定义的节点生态&#xff0c;可以添加各种批量化的能力&#xff0c;这样就有了非常强大的内容生产力。 本期&#xff0c;主要介绍mixlab-nodes的3个生产力节…

《 乱弹篇(二)》

题记 昨&#xff08;2024年1月12日&#xff09;天&#xff0c;既然笔者因感到写时评文力不从心&#xff0c;新辟一专栏《乱弹篇》&#xff0c;开始了“ 东西南北&#xff0c;古今中外&#xff0c;谈而不乱&#xff0c;抒怀而已”的写作路径&#xff0c;就要走下去&#xff0c;…

搭建个人智能家居 2 -安装ESPHome

搭建个人智能家居 2 -安装ESPHome 前言ESPHome Linux平台windows平台总结 前言 上一篇文章我们演示了多个平台下面搭建HomeAssistant&#xff0c;可能有一些小伙伴在安装、运行HomeAssistant OS后&#xff0c;打开HomeAssistant的控制台时会出现下面图片显示的问题 这一般是本…

【面试合集】2.说说微信小程序的生命周期函数有哪些?

面试官&#xff1a;说说微信小程序的生命周期函数有哪些&#xff1f; 一、是什么 跟vue、react框架一样&#xff0c;微信小程序框架也存在生命周期&#xff0c;实质也是一堆会在特定时期执行的函数 小程序中&#xff0c;生命周期主要分成了三部分&#xff1a; 应用的生命周期…