在这个网站看到5*7点阵的字库,发现在Arduino显示是垂直镜像效果。
就写了一段程序把其转化成Android的格式,并转化为二进制,方便查看。
这段程序并不是在Arduino IDE运行,是在电脑上用C语言环境运行。
程序很简单,我就不多解释了。
#include
void printb(int val, int n) {
if (n == 2) {
uint8_t v = (uint8_t)val;
printf("B");
for (int i = 7; i >= 0; i--) {
int b = v >> i;
b = b & 1;
printf("%d", b);
}
printf(", ");
} else if (n == 16) {
uint8_t v = (uint8_t)val;
printf("0x%02x, ", v);
}
}
int r2(int v) {
if (v == 1) return 2;
if (v == 2) return 1;
return v;
}
int r4(int v) {
int high = v / 4;
int low = v % 4;
high = r2(high);
low = r2(low);
return low * 4 + high;
}
int reverse(int v) {
int high = v / 16;
int low = v % 16;
high = r4(high);
low = r4(low);
return low * 16 + high;
}
int main(int argc, const char * argv[]) {
// 数据来源 http://bbs.21ic.com/icview-142159-1-1.html
uint8_t fonts[][5] = {
0x00, 0x00, 0x00, 0x00, 0x00,// ' '
0x00, 0x00, 0x5F, 0x00, 0x00,// !
0x00, 0x07, 0x00, 0x07, 0x00,// "
0x14, 0x7F, 0x14, 0x7F, 0x14,// #
0x24, 0x2A, 0x07, 0x2A, 0x12,// $
0x23, 0x13, 0x08, 0x64, 0x62,// %
0x37, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x1C, 0x22, 0x41, 0x00,// (
0x00, 0x41, 0x22, 0x1C, 0x00,// )
0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x50, 0x30, 0x00, 0x00,// ,
0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x60, 0x60, 0x00, 0x00,// .
0x20, 0x10, 0x08, 0x04, 0x02,// /
0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41,// <
0x14, 0x14, 0x14, 0x14, 0x14,// =
0x41, 0x22, 0x14, 0x08, 0x00,// >
0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x32, 0x49, 0x79, 0x41, 0x3E,// @
0x7E, 0x11, 0x11, 0x11, 0x7E,// A
0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x7F, 0x09, 0x09, 0x01, 0x01,// F
0x3E, 0x41, 0x41, 0x51, 0x32,// G
0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x7F, 0x02, 0x04, 0x02, 0x7F,// M
0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x46, 0x49, 0x49, 0x49, 0x31,// S
0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x7F, 0x20, 0x18, 0x20, 0x7F,// W
0x63, 0x14, 0x08, 0x14, 0x63,// X
0x03, 0x04, 0x78, 0x04, 0x03,// Y
0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41,// [
0x02, 0x04, 0x08, 0x10, 0x20,// "\"
0x41, 0x41, 0x7F, 0x00, 0x00,// ]
0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x01, 0x02, 0x04, 0x00,// `
0x20, 0x54, 0x54, 0x54, 0x78,// a
0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x38, 0x44, 0x44, 0x44, 0x20,// c
0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x38, 0x54, 0x54, 0x54, 0x18,// e
0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x08, 0x14, 0x54, 0x54, 0x3C,// g
0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x20, 0x40, 0x44, 0x3D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44,// k
0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x38, 0x44, 0x44, 0x44, 0x38,// o
0x7C, 0x14, 0x14, 0x14, 0x08,// p
0x08, 0x14, 0x14, 0x18, 0x7C,// q
0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x48, 0x54, 0x54, 0x54, 0x20,// s
0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x44, 0x28, 0x10, 0x28, 0x44,// x
0x0C, 0x50, 0x50, 0x50, 0x3C,// y
0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x00, 0x08, 0x36, 0x41, 0x00,// {
0x00, 0x00, 0x7F, 0x00, 0x00,// |
0x00, 0x41, 0x36, 0x08, 0x00,// }
0x02, 0x01, 0x02, 0x04, 0x02,// ~
0xff, 0xff, 0xff, 0xff, 0xff //black block// �
};
int len = sizeof(fonts) / sizeof(int8_t) / 5;
printf("byte chars[][6] = {\n");
for (int i = 0; i < len ; i++) {
printf("0, "); // 前面增加一列0
for (int j = 0; j < 5; j++) {
int value = fonts[i][j];
value = reverse(value);
// printb(value, 16); // 用十六进制
printb(value, 2); // 用二进制显示
}
printf("// %c\n", i + 32);
}
printf("}\n");
return 0;
}
运行结果为
byte chars[][6] = {
0, B00000000, B00000000, B00000000, B00000000, B00000000, //
0, B00000000, B00000000, B11111010, B00000000, B00000000, // !
0, B00000000, B11100000, B00000000, B11100000, B00000000, // "
0, B00101000, B11111110, B00101000, B11111110, B00101000, // #
0, B00100100, B01010100, B11100000, B01010100, B01001000, // $
0, B11000100, B11001000, B00010000, B00100110, B01000110, // %
0, B11101100, B10010010, B10101010, B01000100, B00001010, // &
0, B00000000, B10100000, B11000000, B00000000, B00000000, // '
0, B00000000, B00111000, B01000100, B10000010, B00000000, // (
0, B00000000, B10000010, B01000100, B00111000, B00000000, // )
0, B00010000, B01010100, B00111000, B01010100, B00010000, // *
0, B00010000, B00010000, B01111100, B00010000, B00010000, // +
0, B00000000, B00001010, B00001100, B00000000, B00000000, // ,
0, B00010000, B00010000, B00010000, B00010000, B00010000, // -
0, B00000000, B00000110, B00000110, B00000000, B00000000, // .
0, B00000100, B00001000, B00010000, B00100000, B01000000, // /
0, B01111100, B10001010, B10010010, B10100010, B01111100, // 0
0, B00000000, B01000010, B11111110, B00000010, B00000000, // 1
0, B01000010, B10000110, B10001010, B10010010, B01100010, // 2
0, B10000100, B10000010, B10100010, B11010010, B10001100, // 3
0, B00011000, B00101000, B01001000, B11111110, B00001000, // 4
0, B11100100, B10100010, B10100010, B10100010, B10011100, // 5
0, B00111100, B01010010, B10010010, B10010010, B00001100, // 6
0, B10000000, B10001110, B10010000, B10100000, B11000000, // 7
0, B01101100, B10010010, B10010010, B10010010, B01101100, // 8
0, B01100000, B10010010, B10010010, B10010100, B01111000, // 9
0, B00000000, B01101100, B01101100, B00000000, B00000000, // :
0, B00000000, B01101010, B01101100, B00000000, B00000000, // ;
0, B00000000, B00010000, B00101000, B01000100, B10000010, // <
0, B00101000, B00101000, B00101000, B00101000, B00101000, // =
0, B10000010, B01000100, B00101000, B00010000, B00000000, // >
0, B01000000, B10000000, B10001010, B10010000, B01100000, // ?
0, B01001100, B10010010, B10011110, B10000010, B01111100, // @
0, B01111110, B10001000, B10001000, B10001000, B01111110, // A
0, B11111110, B10010010, B10010010, B10010010, B01101100, // B
0, B01111100, B10000010, B10000010, B10000010, B01000100, // C
0, B11111110, B10000010, B10000010, B01000100, B00111000, // D
0, B11111110, B10010010, B10010010, B10010010, B10000010, // E
0, B11111110, B10010000, B10010000, B10000000, B10000000, // F
0, B01111100, B10000010, B10000010, B10001010, B01001100, // G
0, B11111110, B00010000, B00010000, B00010000, B11111110, // H
0, B00000000, B10000010, B11111110, B10000010, B00000000, // I
0, B00000100, B00000010, B10000010, B11111100, B10000000, // J
0, B11111110, B00010000, B00101000, B01000100, B10000010, // K
0, B11111110, B00000010, B00000010, B00000010, B00000010, // L
0, B11111110, B01000000, B00100000, B01000000, B11111110, // M
0, B11111110, B00100000, B00010000, B00001000, B11111110, // N
0, B01111100, B10000010, B10000010, B10000010, B01111100, // O
0, B11111110, B10010000, B10010000, B10010000, B01100000, // P
0, B01111100, B10000010, B10001010, B10000100, B01111010, // Q
0, B11111110, B10010000, B10011000, B10010100, B01100010, // R
0, B01100010, B10010010, B10010010, B10010010, B10001100, // S
0, B10000000, B10000000, B11111110, B10000000, B10000000, // T
0, B11111100, B00000010, B00000010, B00000010, B11111100, // U
0, B11111000, B00000100, B00000010, B00000100, B11111000, // V
0, B11111110, B00000100, B00011000, B00000100, B11111110, // W
0, B11000110, B00101000, B00010000, B00101000, B11000110, // X
0, B11000000, B00100000, B00011110, B00100000, B11000000, // Y
0, B10000110, B10001010, B10010010, B10100010, B11000010, // Z
0, B00000000, B00000000, B11111110, B10000010, B10000010, // [
0, B01000000, B00100000, B00010000, B00001000, B00000100, // \
0, B10000010, B10000010, B11111110, B00000000, B00000000, // ]
0, B00100000, B01000000, B10000000, B01000000, B00100000, // ^
0, B00000010, B00000010, B00000010, B00000010, B00000010, // _
0, B00000000, B10000000, B01000000, B00100000, B00000000, // `
0, B00000100, B00101010, B00101010, B00101010, B00011110, // a
0, B11111110, B00010010, B00100010, B00100010, B00011100, // b
0, B00011100, B00100010, B00100010, B00100010, B00000100, // c
0, B00011100, B00100010, B00100010, B00010010, B11111110, // d
0, B00011100, B00101010, B00101010, B00101010, B00011000, // e
0, B00010000, B01111110, B10010000, B10000000, B01000000, // f
0, B00010000, B00101000, B00101010, B00101010, B00111100, // g
0, B11111110, B00010000, B00100000, B00100000, B00011110, // h
0, B00000000, B00100010, B10111110, B00000010, B00000000, // i
0, B00000100, B00000010, B00100010, B10111100, B00000000, // j
0, B00000000, B11111110, B00001000, B00010100, B00100010, // k
0, B00000000, B10000010, B11111110, B00000010, B00000000, // l
0, B00111110, B00100000, B00011000, B00100000, B00011110, // m
0, B00111110, B00010000, B00100000, B00100000, B00011110, // n
0, B00011100, B00100010, B00100010, B00100010, B00011100, // o
0, B00111110, B00101000, B00101000, B00101000, B00010000, // p
0, B00010000, B00101000, B00101000, B00011000, B00111110, // q
0, B00111110, B00010000, B00100000, B00100000, B00010000, // r
0, B00010010, B00101010, B00101010, B00101010, B00000100, // s
0, B00100000, B11111100, B00100010, B00000010, B00000100, // t
0, B00111100, B00000010, B00000010, B00000100, B00111110, // u
0, B00111000, B00000100, B00000010, B00000100, B00111000, // v
0, B00111100, B00000010, B00001100, B00000010, B00111100, // w
0, B00100010, B00010100, B00001000, B00010100, B00100010, // x
0, B00110000, B00001010, B00001010, B00001010, B00111100, // y
0, B00100010, B00100110, B00101010, B00110010, B00100010, // z
0, B00000000, B00010000, B01101100, B10000010, B00000000, // {
0, B00000000, B00000000, B11111110, B00000000, B00000000, // |
0, B00000000, B10000010, B01101100, B00010000, B00000000, // }
0, B01000000, B10000000, B01000000, B00100000, B01000000, // ~
0, B11111111, B11111111, B11111111, B11111111, B11111111, // �
}