前段時間做的專案,從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; }
程式碼執行結果:
軟體很簡單,希望對大家有用