联系方式 Contact


苏州高沃电子有限公司

SUZHOU GOVO TEK LIMITED


地址:苏州市吴中经济开发区天鹅荡路2号友新工业园B3栋3楼

邮编:215000

电话:0512-66035036

传真:0512-66035035

手机:吴先生 15851445511

邮件:sales@govotek.com

网址:http://www.govotek.com

搜索 Search
你的位置:首页 > 新闻动态 > 专题报道

TFT液晶屏使用自建的英文字库

2018-11-20 16:50:07点击:
现在大部分液晶屏是不带字库的,需要吸入文字的时候,需要像画画那样,一个一个点的写,最简单的方法是需要写某个字符,就对某个字符取模,但这样灵活性太差了,下面介绍一种方法,自建字库以及驱动程式,前台应用时直接调用就好了。


首先是建立字库


字库的基本组成单元如下的结构体:


// ------------------  英文字模的数据结构定义 ------------------------ //
struct EnCharType                 // 英文字模数据结构 
{
unsigned char  Msk[12];             // 点阵码数据(12*8有12个数据) 
unsigned char  Index;            // 索引
};


取英文字模的方法说明:
从第一行开始向右每取8个点作为一个字节,如果最后不足8个点就补满8位。
 取模顺序是从高到低,即第一个点作为最高位。如*-------取为10000000


英文字符索引表就是一个由多个字符组成的结构体数组,注意最后一个字符一定要是空格,表示数组查询结束  如下:


struct EnCharType code en_char[] = 
{
0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x18,0x00,0x00,'!',//0
0x00,0x12,0x24,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'"',//1
0x00,0x00,0x24,0x24,0xFE,0x48,0x48,0xFE,0x48,0x48,0x00,0x00,'#',//2
0x00,0x10,0x3C,0x54,0x50,0x30,0x18,0x14,0x54,0x78,0x10,0x00,'$',//3
0x00,0x00,0xE4,0xA4,0xA8,0xF0,0x1E,0x2A,0x2A,0x4E,0x00,0x00,'%',//4
0x00,0x00,0x30,0x48,0x48,0x7E,0xA4,0x94,0x88,0x77,0x00,0x00,'&',//5
0x00,0x60,0x20,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'\'',//6
0x00,0x02,0x0C,0x08,0x10,0x10,0x10,0x10,0x08,0x08,0x06,0x00,'(',//7
0x00,0x40,0x20,0x10,0x08,0x08,0x08,0x08,0x10,0x20,0x40,0x00,')',//8
0x00,0x00,0x00,0x10,0x92,0x7C,0x7C,0x92,0x10,0x00,0x00,0x00,'*',//9
0x00,0x00,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x00,0x00,0x00,'+',//10
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x20,0x40,',',//11
0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,'-',//12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,'.',//13
0x00,0x01,0x02,0x06,0x04,0x08,0x08,0x10,0x20,0x20,0x40,0x00,'/',//14
0x00,0x00,0x3C,0x24,0x42,0x42,0x42,0x42,0x24,0x3C,0x00,0x00,'0',//15
0x00,0x00,0x10,0x70,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,'1',//16
0x00,0x00,0x3C,0x42,0x42,0x04,0x08,0x10,0x62,0x7E,0x00,0x00,'2',//17
0x00,0x00,0x3C,0x42,0x02,0x1C,0x02,0x02,0x42,0x3C,0x00,0x00,'3',//18
0x00,0x00,0x0C,0x14,0x24,0x44,0x44,0x3C,0x04,0x0C,0x00,0x00,'4',//19
0x00,0x00,0x7E,0x40,0x40,0x7C,0x02,0x02,0x42,0x3C,0x00,0x00,'5',//20
0x00,0x00,0x1C,0x24,0x40,0x5C,0x62,0x42,0x62,0x3C,0x00,0x00,'6',//21
0x00,0x00,0x7E,0x44,0x08,0x08,0x10,0x10,0x10,0x10,0x00,0x00,'7',//22
0x00,0x00,0x3C,0x42,0x42,0x34,0x2C,0x42,0x42,0x3C,0x00,0x00,'8',//23
0x00,0x00,0x18,0x64,0x42,0x46,0x3A,0x02,0x24,0x3C,0x00,0x00,'9',//24
0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,':',//25
0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x10,0x00,';',//26
0x00,0x02,0x04,0x18,0x20,0x40,0x20,0x10,0x0C,0x02,0x00,0x00,'<',//27
0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,'=',//28
0x00,0x40,0x20,0x18,0x04,0x02,0x04,0x08,0x30,0x40,0x00,0x00,'>',//29
0x00,0x00,0x3C,0x42,0x62,0x02,0x0C,0x08,0x00,0x18,0x00,0x00,'?',//30
0x00,0x00,0x3C,0x46,0x9A,0xAA,0xAA,0xBC,0x40,0x3E,0x00,0x00,'@',//31
0x00,0x00,0x10,0x18,0x28,0x24,0x24,0x7C,0x42,0xE7,0x00,0x00,'A',//32
0x00,0x00,0xF8,0x44,0x44,0x78,0x46,0x42,0x42,0xFC,0x00,0x00,'B',//33
0x00,0x00,0x3E,0x42,0x80,0x80,0x80,0x80,0x42,0x3C,0x00,0x00,'C',//34
0x00,0x00,0xF8,0x44,0x42,0x42,0x42,0x42,0x44,0xF8,0x00,0x00,'D',//35
0x00,0x00,0xFC,0x42,0x48,0x78,0x48,0x40,0x42,0xFC,0x00,0x00,'E',//36
0x00,0x00,0xFC,0x42,0x48,0x78,0x48,0x40,0x40,0xE0,0x00,0x00,'F',//37
0x00,0x00,0x3C,0x44,0x80,0x80,0x8E,0x84,0x44,0x38,0x00,0x00,'G',//38
0x00,0x00,0xE7,0x42,0x42,0x7E,0x42,0x42,0x42,0xE7,0x00,0x00,'H',//39
0x00,0x00,0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,'I',//40
0x00,0x00,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x88,0xF0,0x00,'J',//41
0x00,0x00,0xEE,0x44,0x48,0x70,0x50,0x48,0x44,0xEE,0x00,0x00,'K',//42
0x00,0x00,0xE0,0x40,0x40,0x40,0x40,0x40,0x42,0xFE,0x00,0x00,'L',//43
0x00,0x00,0xEE,0x6C,0x6C,0x6C,0x54,0x54,0x54,0xD6,0x00,0x00,'M',//44
0x00,0x00,0xC7,0x62,0x52,0x52,0x4A,0x46,0x46,0xE2,0x00,0x00,'N',//45
0x00,0x00,0x3C,0x44,0x82,0x82,0x82,0x82,0x44,0x38,0x00,0x00,'O',//46
0x00,0x00,0xFC,0x42,0x42,0x7C,0x40,0x40,0x40,0xE0,0x00,0x00,'P',//47
0x00,0x00,0x38,0x44,0x82,0x82,0x82,0xB2,0x4C,0x38,0x06,0x00,'Q',//48
0x00,0x00,0xFC,0x42,0x42,0x7C,0x48,0x44,0x46,0xE3,0x00,0x00,'R',//49
0x00,0x00,0x3E,0x42,0x40,0x38,0x04,0x02,0x42,0x7C,0x00,0x00,'S',//50
0x00,0x00,0xFE,0x92,0x10,0x10,0x10,0x10,0x10,0x38,0x00,0x00,'T',//51
0x00,0x00,0xE7,0x42,0x42,0x42,0x42,0x42,0x42,0x3C,0x00,0x00,'U',//52
0x00,0x00,0xE7,0x42,0x44,0x24,0x2C,0x28,0x18,0x10,0x00,0x00,'V',//53
0x00,0x00,0xD6,0x92,0x92,0x92,0x9A,0x6C,0x64,0x44,0x00,0x00,'W',//54
0x00,0x00,0xE7,0x66,0x24,0x18,0x18,0x24,0x66,0xE7,0x00,0x00,'X',//55
0x00,0x00,0xEE,0x44,0x28,0x38,0x10,0x10,0x10,0x38,0x00,0x00,'Y',//56
0x00,0x00,0x7E,0x84,0x08,0x10,0x10,0x20,0x42,0xFC,0x00,0x00,'Z',//57
0x00,0x1E,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1E,0x00,'[',//58
0x00,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x04,0x04,0x02,0x00,'\\',//59
0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x78,0x00,']',//60
0x00,0x1C,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'^',//61
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,'_',//62
0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'`',//63
0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x3E,0x42,0x3F,0x00,0x00,'a',//64
0x00,0x00,0xC0,0x40,0x40,0x5C,0x62,0x42,0x42,0x7C,0x00,0x00,'b',//65
0x00,0x00,0x00,0x00,0x00,0x3C,0x62,0x40,0x42,0x3C,0x00,0x00,'c',//66
0x00,0x00,0x06,0x02,0x02,0x1E,0x62,0x42,0x42,0x3F,0x00,0x00,'d',//67
0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x7E,0x40,0x3E,0x00,0x00,'e',//68
0x00,0x00,0x0F,0x10,0x10,0x7E,0x10,0x10,0x10,0x7C,0x00,0x00,'f',//69
0x00,0x00,0x00,0x00,0x00,0x3E,0x44,0x38,0x40,0x7C,0x42,0x3C,'g',//70
0x00,0x00,0xC0,0x40,0x40,0x5C,0x62,0x42,0x42,0xE7,0x00,0x00,'h',//71
0x00,0x00,0x30,0x00,0x00,0x70,0x10,0x10,0x10,0x7C,0x00,0x00,'i',//72
0x00,0x00,0x0C,0x00,0x00,0x1C,0x04,0x04,0x04,0x04,0x04,0x78,'j',//73
0x00,0x00,0xC0,0x40,0x40,0x4E,0x58,0x70,0x48,0xEE,0x00,0x00,'k',//74
0x00,0x00,0x70,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00,0x00,'l',//75
0x00,0x00,0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0xED,0x00,0x00,'m',//76
0x00,0x00,0x00,0x00,0x00,0xD8,0x66,0x42,0x42,0xE7,0x00,0x00,'n',//77
0x00,0x00,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x3C,0x00,0x00,'o',//78
0x00,0x00,0x00,0x00,0x00,0xF8,0x46,0x42,0x42,0x7C,0x40,0xE0,'p',//79
0x00,0x00,0x00,0x00,0x00,0x3E,0x42,0x42,0x42,0x3E,0x02,0x07,'q',//80
0x00,0x00,0x00,0x00,0x00,0xEE,0x30,0x20,0x20,0xF8,0x00,0x00,'r',//81
0x00,0x00,0x00,0x00,0x00,0x3E,0x40,0x3C,0x42,0x7C,0x00,0x00,'s',//82
0x00,0x00,0x00,0x10,0x10,0x7C,0x10,0x10,0x10,0x0C,0x00,0x00,'t',//83
0x00,0x00,0x00,0x00,0x00,0xC6,0x42,0x42,0x42,0x3F,0x00,0x00,'u',//84
0x00,0x00,0x00,0x00,0x00,0xE7,0x46,0x24,0x28,0x10,0x00,0x00,'v',//85
0x00,0x00,0x00,0x00,0x00,0xD7,0x92,0x9A,0x6A,0x44,0x00,0x00,'w',//86
0x00,0x00,0x00,0x00,0x00,0x6E,0x3C,0x18,0x3C,0x76,0x00,0x00,'x',//87
0x00,0x00,0x00,0x00,0x00,0xE7,0x46,0x24,0x18,0x18,0x10,0xE0,'y',//88
0x00,0x00,0x00,0x00,0x00,0x7E,0x44,0x18,0x32,0x7E,0x00,0x00,'z',//89
0x00,0x07,0x04,0x04,0x04,0x08,0x04,0x04,0x04,0x04,0x03,0x00,'{',//90
0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,'|',//91
0x00,0x70,0x10,0x10,0x10,0x08,0x10,0x10,0x10,0x10,0x60,0x00,'}',//92
0x30,0x4C,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,'~',//93
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' ',//94
};


下面就是说明如何写软件驱动来直接写到TFT屏上,关键是如下几个函数:
1、ShowString 为接口函数,外面直接调用它就好了,支持自动换行


/*******************************************************************************
* 函 数 名 :ShowString
* 函数功能 :显示字符串,可以中英文混合写,根据ASCII码表
* 输    入 :x,y 坐标位置   str 要显示的字符串  dcolor前景色 bgcolor 背景色
* 输    出 :无
*******************************************************************************/
void ShowString(unsigned int x,unsigned int y,unsigned char *str,unsigned int dcolor,unsigned int bgcolor)
{  
unsigned int x1,y1;
x1=x;
y1=y;
while(*str!='\0')
{
ShowEnChar(x1,y1,*str,dcolor,bgcolor);
x1+=8;
if(x1+8 >= 240)//换行
{
x1 = x;
y1 = y1+12;
}
str++;
}
}


2、ShowEnChar 在指定位置显示一个字符,通过要显示的字符来搜索字库,找到其对应的字库,注意以空格结尾,对找不到的也以空格替换
/*******************************************************************************
* 函 数 名 :ShowEnChar
* 函数功能 :在指定位置显示一个英文字符 8*12大小
* 输    入 :x,y 坐标  value 要显示的字符  dcolor前景色 bgcolor 背景色
* 输    出 :无
*******************************************************************************/
void ShowEnChar(unsigned int x,unsigned int y,unsigned char value,unsigned int dcolor,unsigned int bgcolor)
{  
unsigned char i,j;
int index; 

if(x+8 > 240) return ;
if(y+12 > 320) return ;//超出范围,返回

index = SearchEnPosition(value);

  AddressSet(x,y,x+7,y+11); //设置区域      
for(j=0;j<12;j++)
{
for(i=0;i<8;i++)
{      
if((en_char[index].Msk[j] & (1<<(7-i)))!=0)//高位开始
{
LcdWriteData(dcolor>>8,dcolor);

else
{
LcdWriteData(bgcolor>>8,bgcolor);
}   
}
}
}
/*******************************************************************************
* 函 数 名 :SearchEnPosition
* 函数功能 :查找英文字符索引
* 输    入 :value
* 输    出 :在en_char的位置
*******************************************************************************/
int SearchEnPosition(unsigned char value)
{
<span style="white-space:pre"> </span>int i=0;
<span style="white-space:pre"> </span>while(en_char[i].Index != ' ')
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>if(en_char[i].Index == value) return i;
<span style="white-space:pre"> </span>i++;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>return i;
}


在实际使用,就只需要知道其实位置,然后调用ShowString 函数就好了,英文字符不想中文字符,可以把常用的英文字符建立到字库中,底层驱动也是很简单的,以后有空再把相关的工程上传上来