forked from XAS-712/gt20l16s1y
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGT20L16S1Y.c
170 lines (160 loc) · 3.91 KB
/
GT20L16S1Y.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <SPI.h>
#define CS 10
#define SO 11
#define SI 12
#define CL 13
long getAddr(uint16_t str)
{
byte hb = (byte)((str & 0xff00) >> 8);
byte lb = (byte)(str & 0x00ff);
Serial.print("HB ");
Serial.print(hb, HEX);
Serial.print(" LB ");
Serial.println(lb, HEX);
long Address;
if (hb > 0xA0 && lb > 0xA0)//is GB2312
{
long BaseAdd = 0;
if (hb == 0xA9 && lb >= 0xA1)
{
Address = (282 + (lb - 0xA1 ));//8位机在此出现了溢出,所以分三步
Address = Address * 32;
Address += BaseAdd;
}
else if (hb >= 0xA1 && hb <= 0xA3 && lb >= 0xA1)
{
Address = ((hb - 0xA1) * 94 + (lb - 0xA1));
Address = Address * 32;
Address += BaseAdd;
}
else if (hb >= 0xB0 && hb <= 0xF7 && lb >= 0xA1)
{
Address = ((hb - 0xB0) * 94 + (lb - 0xA1) + 846);
Address = Address * 32;
Address += BaseAdd;
}
} else {//is ASCII
long BaseAdd = 0x03b7c0;
if (lb >= 0x20 && lb <= 0x7E)
{
Address = (lb - 0x20 ) * 16 + BaseAdd;
}
}
return Address;
}
byte revBit(byte input)
{
byte output = 0;
for (int i = 0; i < 8; i++)
{
if (input & (1 << i))
output |= 1 << (7 - i);
}
return output;
}
void fetchBitmap16(long address, byte *p)
{
byte hb = (byte)((address & 0x00ff0000) >> 16);
byte mb = (byte)((address & 0x0000ff00) >> 8);
byte lb = (byte)(address & 0x000000ff);
digitalWrite(CS, LOW);//选通字库
SPI.transfer(0x0b);//移入命令字
SPI.transfer(hb);//移入地址次高位
SPI.transfer(mb);//移入地址次低位
SPI.transfer(lb);//移入地址最低位
SPI.transfer(0x8d);//移入dummy byte
for (int i = 0; i < 16; i++)
{
byte buf = SPI.transfer(0x00); //读出16bytes
p[i] = revBit(buf);
}
digitalWrite(CS, HIGH);//反选通字库
}
void fetchBitmap32(long address, byte *p)
{
byte hb = (byte)((address & 0x00ff0000) >> 16);
byte mb = (byte)((address & 0x0000ff00) >> 8);
byte lb = (byte)(address & 0x000000ff);
digitalWrite(CS, LOW);//选通字库
SPI.transfer(0x0b);//移入命令字
SPI.transfer(hb);//移入地址次高位
SPI.transfer(mb);//移入地址次低位
SPI.transfer(lb);//移入地址最低位
SPI.transfer(0x8d);//移入dummy byte
for (int i = 0; i < 32; i++)
{
byte buf = SPI.transfer(0x00); //读出32bytes
p[i] = revBit(buf);
}
digitalWrite(CS, HIGH);//反选通字库
}
void drawV8P(xint x, int y, byte b)
{
if ((b & 0x80) == 0x80)
u8g.drawPixel(x, y);
if ((b & 0x40) == 0x40)
u8g.drawPixel(x, y + 1);
if ((b & 0x20) == 0x20)
u8g.drawPixel(x, y + 2);
if ((b & 0x10) == 0x10)
u8g.drawPixel(x, y + 3);
if ((b & 0x08) == 0x08)
u8g.drawPixel(x, y + 4);
if ((b & 0x04) == 0x04)
u8g.drawPixel(x, y + 5);
if ((b & 0x02) == 0x02)
u8g.drawPixel(x, y + 6);
if ((b & 0x01) == 0x01)
u8g.drawPixel(x, y + 7);
}
void draw8x16(int x, int y, byte *b)
{
int i;
for (i = 0; i < 8; i++)
{
drawV8P(x + i, y, b[i]);
}
for (i = 0; i < 8; i++)
{
drawV8P(x + i, y + 8, b[i + 8]);
}
}
void draw16x16(int x, int y, byte *b)
{
int i;
for (i = 0; i < 16; i++)
{
drawV8P(x + i, y, b[i]);
}
for (i = 0; i < 16; i++)
{
drawV8P(x + i, y + 8, b[i + 16]);
}
}
void displayStr(int x, int y, int len, unsigned char *c)
{
int i;
for (i = 0; i < len; i++)
{
if (c[i] > 0xA0) //is GB2312
{
int code = (int)(c[i] * 256) + (int)c[i + 1];
byte bmp[32];
fetchBitmap32(getAddr(code), bmp);
draw16x16(x, y, bmp);
x += 16;
i++;
} else { //is ASCII
int code = (int)c[i];
byte bmp[16];
fetchBitmap16(getAddr(code), bmp);
draw8x16(x, y, bmp);
x += 8;
}
}
}
void displayStrC(int row, int len, unsigned char *c)
{
int x=64-((len*8)/2);
displayStr(x,row,len,c);
}