前段时间做的项目,从HZK16字库中读取的字模数据是16*16逐行式顺向格式的,传输给客户的设备无法显示,他们那边不能改变OLED屏显示的方式,所以写了一个简单的字模转换算法;
HZK16的读取网上一搜就是一大堆,所以这里就不贴这串代码了;
测试的时候可以使用PCtoLCD工具生成两种不同格式的字模数据对转换后的字模数据进行校对;
{0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x80,0x04,0x1F,0xE0,0x00,0x40,0x00,0x80},
{0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00},/*"字",0*/
{0x10,0x0C,0x04,0x24,0x24,0x24,0x25,0x26,0xA4,0x64,0x24,0x04,0x04,0x14,0x0C,0x00},
{0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00},/*"字",0*/
================================================================================================================
软件代码:
代码复制到C-Free可以直接使用
#include "stdio.h" #include "string.h" #include "stdlib.h" #define T 0X80 void reverseAndConvert(unsigned char *input, unsigned char *output) { int i = 0; for(i = 0;i<8;i++) { output[i] = ((input[0]&T>>i)<<i)>>7; output[i] += ((input[2]&T>>i)<<i)>>6; output[i] += ((input[4]&T>>i)<<i)>>5; output[i] += ((input[6]&T>>i)<<i)>>4; output[i] += ((input[8]&T>>i)<<i)>>3; output[i] += ((input[10]&T>>i)<<i)>>2; output[i] += ((input[12]&T>>i)<<i)>>1; output[i] += ((input[14]&T>>i)<<i); output[i+8] = ((input[1]&T>>i)<<i)>>7; output[i+8] += ((input[3]&T>>i)<<i)>>6; output[i+8] += ((input[5]&T>>i)<<i)>>5; output[i+8] += ((input[7]&T>>i)<<i)>>4; output[i+8] += ((input[9]&T>>i)<<i)>>3; output[i+8] += ((input[11]&T>>i)<<i)>>2; output[i+8] += ((input[13]&T>>i)<<i)>>1; output[i+8] += ((input[15]&T>>i)<<i); output[i+16] = ((input[16]&T>>i)<<i)>>7; output[i+16] += ((input[18]&T>>i)<<i)>>6; output[i+16] += ((input[20]&T>>i)<<i)>>5; output[i+16] += ((input[22]&T>>i)<<i)>>4; output[i+16] += ((input[24]&T>>i)<<i)>>3; output[i+16] += ((input[26]&T>>i)<<i)>>2; output[i+16] += ((input[28]&T>>i)<<i)>>1; output[i+16] += ((input[30]&T>>i)<<i); output[i+24] = ((input[17]&T>>i)<<i)>>7; output[i+24] += ((input[19]&T>>i)<<i)>>6; output[i+24] += ((input[21]&T>>i)<<i)>>5; output[i+24] += ((input[23]&T>>i)<<i)>>4; output[i+24] += ((input[25]&T>>i)<<i)>>3; output[i+24] += ((input[27]&T>>i)<<i)>>2; output[i+24] += ((input[29]&T>>i)<<i)>>1; output[i+24] += ((input[31]&T>>i)<<i); } } /* 字模格式:阴码、顺向、逐行式、16X16 {0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x80,0x04,0x1F,0xE0,0x00,0x40,0x00,0x80, 0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00} 字模格式:阴码、逆向、列行式、16X16 {0x10,0x0C,0x04,0x24,0x24,0x24,0x25,0x26,0xA4,0x64,0x24,0x04,0x04,0x14,0x0C,0x00, 0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00} */ int main(void) { unsigned char in_char[32] = {0x02,0x00,0x01,0x00,0x7F,0xFE,0x40,0x02,0x80,0x04,0x1F,0xE0,0x00,0x40,0x00,0x80, 0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00}; unsigned char out_char[32] = {0}; int i = 0; reverseAndConvert(in_char,out_char); printf("in_char:\n"); for(i = 0; i < 32; i++) { printf("%02x ",in_char[i]); } printf("\nout_char:\n"); for(i = 0; i < 32; i++) { printf("%02x ",out_char[i]); } printf("\n"); return 0; }
代码运行结果:
软件很简单,希望对大家有用
标签:24,16,0x00,0x02,output,input,逐行,阴码 From: https://www.cnblogs.com/xiaoxiaoclassments/p/18441224