微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 如何将将字库或图片以数组的形式储存在.c 文件中

如何将将字库或图片以数组的形式储存在.c 文件中

时间:11-27 来源:互联网 点击:
如果你所用的片上flash为20kB,而需要的汉字库和啊撒可码总共就有4-5kB,又不想用外部flash来储存,当然你是高手的话,下面的你就不用看了,写给新手的。

我们新建一个xx.c文件,利用工具将我们所需要的汉字,字符,标点,生成16进制的数组码表,如下,

#definehzNum109

constunsignedcharhzIndex[218]={

0xc9,0xf9,0xd1,0xb8,0xb5,0xe7,0xd7,0xd3,

0xc9,0xe8,0xd6,0xc3,0xbf,0xec,0xbd,0xdd,

0xc7,0xeb,0xca,0xe4,0xc8,0xeb,0xb2,0xd9,

0xd7,0xf7,0xbf,0xda,0xc1,0xee,0xc8,0xb7,

0xb6,0xa8,0xc8,0xa1,0xcf,0xfb,0xca,0xfd,

0xc9,0xbe,0xb3,0xfd,0xb3,0xb7,0xb7,0xc0,

0xd4,0xda,0xbc,0xd2,0xb2,0xbc,0xcd,0xe2,

0xb3,0xf6,0xd1,0xa1,0xd4,0xf1,0xcd,0xcb,

0xd6,0xd0,0xb8,0xfc,0xb8,0xc4,0xd6,0xd8,

0xb7,0xb5,0xbb,0xd8,0xb1,0xa3,0xb4,0xe6,

0xca,0xc7,0xb7,0xf1,0xcf,0xfa,0xd6,0xf7,

0xd5,0xfd,0xb3,0xa3,0xb5,0xf4,0xb3,0xd8,

0xb3,0xe4,0xb7,0xc5,0xb1,0xa8,0xbe,0xaf,

0xce,0xfc,0xba,0xcf,0xb9,0xca,0xd5,0xcf,

0xcf,0xc2,0xd4,0xd8,0xcd,0xea,0xb3,0xc9,

0xce,0xde,0xb4,0xcb,0xc7,0xf8,0xb7,0xb6,

0xce,0xa7,0xc3,0xdc,0xc2,0xeb,0xa3,0xba,

0xa3,0xac,0xb4,0xed,0xce,0xf3,0xce,0xb4,

0xd0,0xe8,0xb9,0xa6,0xa3,0xa1,0xb2,0xbb,

}

constunsignedcharhzdot[3488]={

/*声CC9F9*/

0x02,0x12,0xD2,0x52,0x52,0x52,0x52,0xDF,

0x52,0x52,0x52,0x52,0xD2,0x12,0x02,0x00,

0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x03,

0x02,0x02,0x02,0x02,0x07,0x00,0x00,0x00,

.

.

.

.

.}

此只是举例而已,切记,此处生成的数组定义时要使用const来定义,不用static和extern,否则编译时仍会报内存不足情况,const就是修饰为常量,编译器通常不为普通const常量分配存储空间,而是将它们保存在符号表中,这使得它成为一个编译期间的常量,没有了存储与读内存的操作,使得它的效率也很高,这就是const的神奇之处。

Xx.c文件中就是这些内容,

Xx.H的内容就是声明和定义了,

#ifndef__xx_H__

#define__xx_H__

#definehzNum109

externconstunsignedcharchardot_8x16[];

externconstunsignedcharhzIndex[];

externconstunsignedcharhzdot[];

#endif

此文件中需要供外部使用,声明前加上extern,在使用的开头,#include”xx.h”就成功了!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top