字库

要在屏幕上显示文字,其实就是在二维点阵上,用一个个点来组成文字。描绘的点的形状不同可以形成不同的字体。

企业微信截图_15779320988763.png

上图中,显示一个“A”用的是16x16的点阵,被画到的点用1表示,未被画到的点用0表示。第一行没有画到点,所以是“00000000,00000000”(二进制)=“0x00,0x00,(十六进制)”,第二行和第三行同理。第四行是“00000001,11000000”==“0x01,0xC0”。以此类推可以得到如下“A”的字模编码。

//A
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x03,0xC0,0x02,0xE0,0x06,0x60,0x04,0x70,
0x0C,0x30,0x0F,0xF8,0x18,0x38,0x10,0x1C,0x30,0x1C,0xFC,0x3F,0x00,0x00,0x00,0x00,

我们按照ASCII码表里的排列顺序,依次提取它们的字模编码。这样做的好处是,我们可以用该字符的ASCII码值算出它在字库里的偏移位置。
offset = (ASCII码 - 32) x 32;
-32表示字库的第一个字符' '的ASCII码为32,
x32表示每个字符在字库数组里占用32个字节

e850352ac65c103880a07b53bc119313b17e8941@wm_1,g_7,k_d2F0ZXIvYmFpa2UxMTY=,xp_5,yp_5.jpg
unsigned char ezkdata[] ={ 

//' '
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,0x01,0x00,0x03,0xC0,0x03,0xC0,0x03,0x80,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,0x03,0xC0,0x03,0xC0,0x00,0x00,0x00,0x00,

//"
0x00,0x00,0x03,0x98,0x07,0xB8,0x0E,0x70,0x18,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,0x00,0x00,0x00,0x04,0x18,0x04,0x18,0x3F,0xFE,0x7F,0xFE,0x0C,0x18,
0x0C,0x18,0x0C,0x10,0x7F,0xFE,0x3F,0xFE,0x18,0x30,0x18,0x30,0x00,0x00,0x00,0x00,

//$
0x00,0x00,0x00,0x00,0x01,0x80,0x07,0xF0,0x19,0xB8,0x19,0xB8,0x1F,0x80,0x0F,0x80,
0x03,0xE0,0x01,0xF8,0x19,0x98,0x3D,0x9C,0x19,0x98,0x0F,0xE0,0x01,0x80,0x00,0x80,

//%
0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x18,0x66,0x10,0xE7,0x20,0xE6,0x40,0x66,0xC0,
0x3D,0xBC,0x03,0x66,0x02,0xE6,0x04,0xE6,0x08,0x66,0x18,0x3C,0x00,0x00,0x00,0x00,

//&
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x80,0x18,0xC0,0x18,0xC0,0x19,0x80,0x1F,0x3C,
0x3E,0x3C,0x66,0x10,0xE3,0xB0,0xE1,0xE0,0x70,0xF1,0x3F,0xBE,0x00,0x00,0x00,0x00,

//'
0x00,0x00,0x1C,0x00,0x1E,0x00,0x0C,0x00,0x38,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,0x18,0x00,0x30,0x00,0xE0,0x00,0xC0,0x01,0xC0,0x01,0x80,
0x01,0x80,0x01,0x80,0x01,0xC0,0x00,0xC0,0x00,0x60,0x00,0x30,0x00,0x0C,0x00,0x04,

//)
0x00,0x00,0x60,0x00,0x18,0x00,0x0C,0x00,0x06,0x00,0x03,0x00,0x03,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x03,0x80,0x03,0x00,0x06,0x00,0x0C,0x00,0x30,0x00,0x20,0x00,

//*
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0xC0,0x79,0x9E,0x3F,0xFC,
0x07,0xF0,0x7D,0xBE,0x31,0x8E,0x01,0xC0,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,

//+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x01,0x80,0x3F,0xFE,
0x3F,0xFE,0x01,0x80,0x01,0x80,0x01,0x80,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,0x08,0x00,0x3C,0x00,0x1E,0x00,0x0C,0x00,0x38,0x00,

//-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFE,
0x3F,0xFE,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,0x3C,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,

///
0x00,0x00,0x00,0x02,0x00,0x06,0x00,0x0C,0x00,0x18,0x00,0x30,0x00,0x60,0x00,0xC0,
0x01,0x80,0x03,0x00,0x06,0x00,0x0C,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x00,0x00,

//0
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x1C,0x38,0x38,0x1C,0x38,0x1C,0x78,0x1E,
0x78,0x1E,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x1C,0x38,0x07,0xE0,0x00,0x00,0x00,0x00,

//1
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x0F,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,
0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x1F,0xF8,0x00,0x00,0x00,0x00,

//2
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x18,0x18,0x38,0x1C,0x38,0x1C,0x00,0x38,
0x00,0x70,0x01,0xC0,0x07,0x00,0x0C,0x04,0x3F,0xFC,0x3F,0xFC,0x00,0x00,0x00,0x00,

//3
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x38,0x38,0x38,0x18,0x00,0x38,0x03,0xF0,
0x03,0xF0,0x00,0x18,0x00,0x1C,0x38,0x1C,0x38,0x18,0x1F,0xF0,0x00,0x00,0x00,0x00,

//4
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0xF0,0x01,0xF0,0x02,0x70,0x0C,0x70,
0x18,0x70,0x30,0x70,0x3F,0xFE,0x00,0x70,0x00,0x70,0x03,0xFE,0x00,0x00,0x00,0x00,

//5
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x18,0x00,0x18,0x00,0x18,0xC0,0x1F,0xF8,
0x18,0x1C,0x00,0x1C,0x10,0x1C,0x38,0x1C,0x38,0x18,0x0F,0xF0,0x00,0x00,0x00,0x00,

//6
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF8,0x0C,0x38,0x18,0x10,0x38,0x00,0x3F,0xF8,
0x7C,0x1C,0x78,0x0C,0x38,0x0E,0x38,0x0C,0x1C,0x18,0x0F,0xF0,0x00,0x00,0x00,0x00,

//7
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFE,0x38,0x0C,0x30,0x10,0x00,0x30,0x00,0x60,
0x00,0xC0,0x01,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x00,0x00,0x00,0x00,

//8
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x38,0x1C,0x30,0x0C,0x3C,0x1C,0x1F,0xF0,
0x0F,0xF0,0x38,0x78,0x70,0x1C,0x70,0x0C,0x38,0x18,0x0F,0xF0,0x00,0x00,0x00,0x00,

//9
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x38,0x18,0x30,0x1C,0x70,0x1C,0x70,0x1C,
0x38,0x3C,0x1F,0xDC,0x00,0x1C,0x18,0x38,0x3C,0x70,0x1F,0xE0,0x00,0x00,0x00,0x00,

//:
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x03,0xC0,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x03,0x80,0x00,0x00,0x00,0x00,

//;
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x03,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x03,0xC0,0x01,0x80,0x01,0x00,

//<
0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x1C,0x00,0x70,0x01,0xC0,0x07,0x00,0x1C,0x00,
0x38,0x00,0x0E,0x00,0x03,0x80,0x00,0xE0,0x00,0x38,0x00,0x0C,0x00,0x00,0x00,0x00,

//=
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x00,0x00,
0x00,0x00,0x3F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

//>
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x06,0x00,0x01,0xC0,0x00,0x70,0x00,0x1C,
0x00,0x0C,0x00,0x38,0x00,0xE0,0x03,0x80,0x0C,0x00,0x10,0x00,0x00,0x00,0x00,0x00,

//?
0x00,0x00,0x00,0x00,0x01,0x80,0x0F,0xF8,0x30,0x1C,0x38,0x0E,0x38,0x1C,0x00,0x78,
0x00,0xE0,0x01,0x80,0x01,0x80,0x01,0x00,0x03,0xC0,0x03,0xC0,0x00,0x00,0x00,0x00,

//@
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF8,0x1C,0x0C,0x31,0xFE,0x33,0x36,0x76,0x32,
0x76,0x36,0x76,0x76,0x36,0xFC,0x33,0xBA,0x1C,0x0C,0x07,0xF0,0x00,0x00,0x00,0x00,

//A
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x03,0xC0,0x02,0xE0,0x06,0x60,0x04,0x70,
0x0C,0x30,0x0F,0xF8,0x18,0x38,0x10,0x1C,0x30,0x1C,0xFC,0x3F,0x00,0x00,0x00,0x00,

//B
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x3F,0xF8,
0x3F,0xF8,0x38,0x0C,0x38,0x0E,0x38,0x0E,0x38,0x1C,0xFF,0xF8,0x00,0x00,0x00,0x00,

//C
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x1C,0x06,0x38,0x02,0x70,0x00,0x70,0x00,
0x70,0x00,0x70,0x00,0x70,0x02,0x38,0x02,0x1C,0x0C,0x0F,0xF0,0x00,0x00,0x00,0x00,

//D
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xE0,0x38,0x38,0x38,0x1C,0x38,0x0E,0x38,0x0E,
0x38,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x1C,0x38,0x78,0x7F,0xE0,0x00,0x00,0x00,0x00,

//E
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFC,0x18,0x0E,0x18,0x02,0x18,0x10,0x1F,0xF0,
0x1F,0xF0,0x18,0x10,0x18,0x00,0x18,0x02,0x18,0x0E,0x7F,0xFC,0x00,0x00,0x00,0x00,

//F
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x18,0x06,0x18,0x00,0x18,0x18,0x18,0x38,
0x1F,0xF8,0x18,0x18,0x18,0x00,0x18,0x00,0x18,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,

//G
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x1C,0x18,0x38,0x0C,0x70,0x00,0x70,0x00,
0x70,0x00,0x70,0x7E,0x70,0x1C,0x38,0x1C,0x1C,0x1C,0x0F,0xF8,0x00,0x00,0x00,0x00,

//H
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x3E,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1C,
0x3F,0xFC,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x38,0x1C,0x7E,0x3E,0x00,0x00,0x00,0x00,

//I
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x1F,0xF8,0x00,0x00,0x00,0x00,

//J
0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFE,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,
0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x30,0x60,0x78,0xC0,0x3F,0x80,

//K
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x7C,0x38,0x30,0x38,0xE0,0x39,0x80,0x3B,0x80,
0x3D,0xC0,0x38,0xE0,0x38,0x60,0x38,0x30,0x38,0x18,0x7E,0x3E,0x00,0x00,0x00,0x00,

//L
0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x1C,0x00,0x1C,0x00,0x1C,0x00,0x1C,0x00,
0x1C,0x00,0x1C,0x00,0x1C,0x00,0x1C,0x02,0x1C,0x06,0x7F,0xFC,0x00,0x00,0x00,0x00,

//M
0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x1E,0x38,0x1C,0x38,0x3C,0x3C,0x2C,0x2C,0x6C,
0x2E,0x4C,0x26,0xCC,0x26,0x8C,0x23,0x8C,0x23,0x0C,0xFB,0x3F,0x00,0x00,0x00,0x00,

//N
0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x1E,0x3C,0x0C,0x3E,0x0C,0x37,0x0C,0x33,0x8C,
0x31,0xCC,0x30,0xEC,0x30,0x7C,0x30,0x3C,0x30,0x1C,0xFC,0x0C,0x00,0x00,0x00,0x00,

//O
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x1C,0x18,0x38,0x0C,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x30,0x0E,0x38,0x0C,0x1C,0x18,0x07,0xF0,0x00,0x00,0x00,0x00,

//P
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x18,0x1C,0x18,0x0E,0x18,0x0E,0x18,0x1C,
0x1F,0xF0,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,

//Q
0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x18,0x18,0x38,0x0C,0x70,0x0E,0x70,0x0E,
0x70,0x0E,0x70,0x0E,0x73,0x8E,0x3F,0xCC,0x1C,0x78,0x0F,0xF0,0x00,0x3C,0x00,0x08,

//R
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x18,0x1C,0x18,0x1C,0x18,0x1C,0x18,0x78,
0x1F,0xE0,0x18,0xE0,0x18,0x70,0x18,0x30,0x18,0x18,0x7E,0x1F,0x00,0x00,0x00,0x00,

//S
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x30,0x18,0x30,0x08,0x38,0x00,0x1F,0x80,
0x03,0xF0,0x00,0x78,0x00,0x0C,0x20,0x0C,0x38,0x18,0x3F,0xF0,0x00,0x00,0x00,0x00,

//T
0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x61,0x86,0x41,0x82,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x0F,0xF0,0x00,0x00,0x00,0x00,

//U
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x1E,0x38,0x0C,0x38,0x0C,0x38,0x0C,0x38,0x0C,
0x38,0x0C,0x38,0x0C,0x38,0x0C,0x38,0x0C,0x18,0x18,0x0F,0xF0,0x00,0x00,0x00,0x00,

//V
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x1E,0x38,0x08,0x1C,0x18,0x1C,0x10,0x0E,0x30,
0x0E,0x60,0x06,0x60,0x07,0x40,0x03,0xC0,0x03,0x80,0x01,0x00,0x00,0x00,0x00,0x00,

//W
0x00,0x00,0x00,0x00,0x00,0x00,0x7B,0xCF,0x31,0xC6,0x31,0xC4,0x39,0xCC,0x19,0xC8,
0x1B,0xE8,0x1A,0x78,0x1E,0x70,0x0E,0x70,0x0C,0x70,0x0C,0x20,0x00,0x00,0x00,0x00,

//X
0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x3E,0x0C,0x18,0x0E,0x30,0x07,0x60,0x03,0xC0,
0x01,0xC0,0x03,0xE0,0x06,0x70,0x0C,0x38,0x08,0x1C,0x7C,0x3F,0x00,0x00,0x00,0x00,

//Y
0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x3E,0x18,0x18,0x0C,0x10,0x0E,0x20,0x06,0x60,
0x03,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x0F,0xE0,0x00,0x00,0x00,0x00,

//Z
0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x38,0x18,0x20,0x30,0x00,0x60,0x01,0xC0,
0x03,0x80,0x03,0x00,0x0E,0x00,0x1C,0x06,0x38,0x0C,0x7F,0xFC,0x00,0x00,0x00,0x00,

//[
0x00,0x00,0x03,0xFC,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,
0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03,0xFC,0x03,0xFC,

//'\'
0x00,0x00,0x00,0x00,0x10,0x00,0x18,0x00,0x0C,0x00,0x06,0x00,0x03,0x00,0x03,0x80,
0x01,0x80,0x00,0xC0,0x00,0x60,0x00,0x30,0x00,0x38,0x00,0x18,0x00,0x0C,0x00,0x06,

//]
0x00,0x00,0x1F,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,
0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x00,0xC0,0x1F,0xC0,0x1F,0xC0,

//^
0x00,0x00,0x03,0xE0,0x0E,0x30,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,

//`
0x00,0x00,0x1F,0x00,0x03,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,0x00,

//a
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x1C,0x70,
0x38,0x18,0x07,0xF8,0x3E,0x18,0x30,0x18,0x70,0x3B,0x1F,0xFE,0x00,0x00,0x00,0x00,

//b
0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x38,0x00,0x38,0x00,0x39,0xE0,0x3F,0xF8,
0x38,0x1C,0x38,0x0C,0x38,0x0C,0x38,0x0C,0x38,0x18,0x3F,0xF0,0x00,0x00,0x00,0x00,

//c
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xE0,0x0F,0x38,
0x18,0x1C,0x38,0x00,0x38,0x00,0x38,0x04,0x1C,0x0C,0x0F,0xF0,0x00,0x00,0x00,0x00,

//d
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x18,0x00,0x18,0x03,0xD8,0x0E,0x78,
0x38,0x18,0x38,0x18,0x38,0x18,0x38,0x18,0x18,0x38,0x0F,0xFE,0x00,0x00,0x00,0x00,

//e
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xE0,0x0E,0x78,
0x18,0x1C,0x3F,0xFC,0x3F,0xFC,0x38,0x00,0x1C,0x08,0x0F,0xF0,0x00,0x00,0x00,0x00,

//f
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFE,0x03,0x0E,0x07,0x00,0x3F,0xF8,0x3F,0xF8,
0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x3F,0xF0,0x00,0x00,0x00,0x00,

//g
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xCE,0x1E,0x7E,
0x18,0x38,0x18,0x38,0x0F,0xF0,0x19,0x80,0x1F,0xF8,0x30,0x3C,0x30,0x0C,0x1F,0xF8,

//h
0x00,0x00,0x00,0x00,0x08,0x00,0x78,0x00,0x18,0x00,0x18,0x00,0x19,0xE0,0x1F,0xF8,
0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7E,0x7E,0x00,0x00,0x00,0x00,

//i
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x01,0xC0,0x00,0x00,0x0F,0x80,0x0F,0x80,
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x1F,0xF8,0x00,0x00,0x00,0x00,

//j
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x38,0x00,0x00,0x01,0xF8,0x01,0xF8,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x18,0x30,0x1F,0xE0,

//k
0x00,0x00,0x00,0x00,0x08,0x00,0x38,0x00,0x18,0x00,0x18,0x00,0x18,0x7C,0x18,0x7C,
0x18,0xC0,0x1B,0x80,0x1E,0xC0,0x18,0x70,0x18,0x38,0x7E,0x7E,0x00,0x00,0x00,0x00,

//l
0x00,0x00,0x00,0x00,0x00,0x80,0x1F,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x1F,0xF8,0x00,0x00,0x00,0x00,

//m
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x77,0x38,0x7F,0xFE,
0x31,0x8E,0x31,0x8E,0x31,0x8E,0x31,0x8E,0x31,0x8E,0xFB,0xFF,0x00,0x00,0x00,0x00,

//n
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xE0,0x7F,0xF8,
0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7E,0x7E,0x00,0x00,0x00,0x00,

//o
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x1E,0x78,
0x38,0x1C,0x30,0x0C,0x70,0x0E,0x30,0x0C,0x18,0x18,0x0F,0xF0,0x00,0x00,0x00,0x00,

//p
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xE0,0x7F,0xF8,
0x18,0x0C,0x18,0x0E,0x18,0x0E,0x18,0x0C,0x1C,0x1C,0x1F,0xF0,0x18,0x00,0x7E,0x00,

//q
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC8,0x1E,0x78,
0x38,0x18,0x30,0x18,0x30,0x18,0x30,0x18,0x18,0x38,0x0F,0xF8,0x00,0x18,0x00,0x7E,

//r
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x3C,0x7E,0xFE,
0x0F,0x04,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x0E,0x00,0x7F,0xE0,0x00,0x00,0x00,0x00,

//s
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xE8,0x0E,0x78,
0x18,0x08,0x0F,0x80,0x03,0xF8,0x10,0x1C,0x18,0x0C,0x1F,0xF8,0x00,0x00,0x00,0x00,

//t
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x03,0x00,0x3F,0xF0,0x3F,0xF0,
0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x03,0x08,0x01,0xF0,0x00,0x00,0x00,0x00,

//u
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x38,0x78,0x38,
0x38,0x18,0x38,0x18,0x38,0x18,0x38,0x18,0x18,0x38,0x0F,0xDE,0x00,0x00,0x00,0x00,

//v
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x3C,0x3E,0x3C,
0x0C,0x10,0x0E,0x30,0x06,0x60,0x03,0x40,0x03,0x80,0x01,0x80,0x00,0x00,0x00,0x00,

//w
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7B,0xCF,0x7B,0xCF,
0x31,0xCC,0x39,0xCC,0x1B,0xF8,0x1E,0x70,0x0E,0x70,0x0C,0x20,0x00,0x00,0x00,0x00,

//x
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x3C,0x3E,0x3C,
0x07,0x20,0x03,0xC0,0x01,0xC0,0x06,0x60,0x0C,0x38,0x7E,0x7E,0x00,0x00,0x00,0x00,

//y
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x3E,0x3E,0x3E,
0x0C,0x18,0x06,0x30,0x07,0x60,0x03,0xC0,0x01,0xC0,0x01,0x80,0x11,0x00,0x3E,0x00,

//z
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x3F,0xF8,
0x30,0xE0,0x01,0xC0,0x03,0x80,0x06,0x04,0x1C,0x0C,0x3F,0xF8,0x00,0x00,0x00,0x00,

//{
0x00,0x00,0x00,0x3C,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0xE0,
0x01,0xC0,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x60,0x00,0x30,0x00,0x18,

//|
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,

//}
0x00,0x00,0x3C,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x03,0x00,
0x03,0x80,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x0C,0x00,0x18,0x00,

//~
0x0E,0x00,0x3F,0x82,0x60,0xE6,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00


};

如果要显示汉字,因为汉字比较多,制作比较耗时间,可以调用现成网上制作好的HZK16字库,HZK16字库是符合GB2312标准的16×16点阵字库。GB2312标准里将汉字和图形符号排列在一个94行94列的二维代码表中,每个汉字用两个字节编码,第一个字节叫区码,第二个字节叫位码,范围为A1A1~FEFE。
汉字在HZK16中的偏移地址,
offset = (94x(区码-0xA1)+(位码-0xA1))x32。
x32表示每个字符占32个字节

企业微信截图_20200102111800.png

zk.h

/************************************************* 
  Copyright (C), 2013-2019, Xmetc Tech. Co., Ltd. 
  File name:  zk.h  
  Author: cwy        
  Date: 2013-08-21 
  Description: 字库模块头文件
*************************************************/ 
#ifndef __ZK_H__
#define __ZK_H__

//字库数组
extern unsigned char hzkdata[282752]; //(6763+682)*32 HZK16的GB2312-80支持的汉字有6763个,符号682,有很多编码空白区
extern unsigned char ezkdata[3040];   //(126-32+1)*32=3040

void disp_hchar(unsigned int x0,unsigned int y0,char str[],unsigned short frontcolor,unsigned short backcolor);
void disp_str(unsigned int x0,unsigned int y0,char str[],unsigned short frontcolor,unsigned short backcolor);
void disp_echar(unsigned int x0,unsigned int y0,char c,unsigned short frontcolor,unsigned short backcolor);
#endif

zk.c

/************************************************* 
  Copyright (C), 2013-2019, Xmetc Tech. Co., Ltd. 
  File name: zk.c   
  Author: cwy        
  Date: 2013-08-21 
  Description: 字符显示模块 
*************************************************/ 
#include "zk.h"
#include "lcd.h"
#include "timer4.h"
#include "uart.h"

/************************************************* 
  函数名称:  void disp_hchar(unsigned int x0,unsigned int y0,char c[],unsigned short frontcolor,unsigned short backcolor)
  描述:      单个汉字显示函数
  输入参数: (unsigned int x0,unsigned int y0,char c[],unsigned short frontcolor,unsigned short backcolor)                 
  返回值:    无       
  其他:      x0,y0表示汉字要显示的起始位置       
*************************************************/ 
void disp_hchar(unsigned int x0,unsigned int y0,char str[],unsigned short frontcolor,unsigned short backcolor)
{
    unsigned int i,j;
    unsigned char *addr;
    unsigned short temp;
    addr = (unsigned char *)hzkdata + (str[0] - 0xa1)*94*32 + (str[1] - 0xa1)*32;
    
    for(i=0;i<32;i+=2)//控制每个汉字的第几行字模 每次取两个数组元素 共两个字节大小
    {  
        temp = ((*(addr+i))<<8) | (*(addr+i+1));//取出一行的点阵
        for(j=0;j<16;j++)
        {
            if(temp&(1<<(15-j)))
            { 
                paint_pixel(x0+j,y0+(i/2),frontcolor);
            }
            else
            {
                if(backcolor != CLARITY)
                {
                    paint_pixel(x0+j,y0+(i/2),backcolor);
                }
                
            }
        
        }
    }

}


/************************************************* 
  函数名称:  void disp_echar(unsigned int x0,unsigned int y0,char c,unsigned short frontcolor,unsigned short backcolor)
  描述:      单个英文显示函数
  输入参数: (unsigned int x0,unsigned int y0,char c,unsigned short frontcolor,unsigned short backcolor)                 
  返回值:    无       
  其他:      x0,y0表示汉字要显示的起始位置       
*************************************************/ 
void disp_echar(unsigned int x0,unsigned int y0,char c,unsigned short frontcolor,unsigned short backcolor)
{
    unsigned int i,j;
    unsigned char *addr;
    unsigned short temp;
    addr = (unsigned char *)(ezkdata + (c - 32)*32);//计算字符c在字库中的相对地址,每个字符在字库数组里占用32个字节
    
    for(i=0;i<32;i+=2)//控制每个英文字的第几行字模 每次取两个数组元素 共两个字节大小
    {  
        temp = ((*(addr+i))<<8) | (*(addr+i+1));//取出一行的点阵
        for(j=0;j<16;j++)
        {
            if(temp&(1<<(15-j)))
            { paint_pixel(x0+j,y0+(i/2),frontcolor);}
            else
            { 
                if(backcolor != CLARITY)
                {
                    paint_pixel(x0+j,y0+(i/2),backcolor);
                }
            }
        
        }
    }

}




/************************************************* 
  函数名称:  void disp_str(unsigned int x0,unsigned int y0,char c[],unsigned short frontcolor,unsigned short backcolor)
  描述:      字符串显示函数
  输入参数: (unsigned int x0,unsigned int y0,char str[],unsigned short frontcolor,unsigned short backcolor)                 
  返回值:    无       
  其他:      x0,y0表示汉字要显示的起始位置       
*************************************************/ 
void disp_str(unsigned int x0,unsigned int y0,char str[],unsigned short frontcolor,unsigned short backcolor)
{

    unsigned int m = x0;
    unsigned int n = y0;
    char *p = str;
    
    while( (*p) != '\0' )
    {
    
        if( (*p) > 127 )//汉字
        {
            disp_hchar(m,n,p,frontcolor,backcolor);
            //delay_timer4_1ms(100);
            p += 2;
        }
        
        else //英文
        {
            disp_echar(m,n,(*p),frontcolor,backcolor);
            //delay_timer4_1ms(100);
            p += 1;         
        
        }
        
        m = m +16;
        
        if( m > (239-15) )//满行时换行
        {
            m=0;
            n = n + 16;
        }
        
        if( n > (319-15) )//满屏时换屏
        {
            n=0;
            //lcd_clear_scr(0x0);
        }   
            
    }
}

你可能感兴趣的:(字库)