-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathST7920.h
278 lines (197 loc) · 7.15 KB
/
ST7920.h
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* ************************************************************************
*
* ST7920 graphic display controller with built-in fonts
*
* (c) 2017-2020 by Markus Reschke
*
* ************************************************************************ */
/* ************************************************************************
* addresses
* ************************************************************************ */
/*
* CGROM
* - 8192 Chinese characters 16x16
* - BIG5: traditional character set
* - GB: simplified character set
*/
#define CGROM_BIG5_START 0xA140
#define CGROM_BIG5_END 0xD75F
#define CGROM_GB_START 0xA1A0
#define CGROM_GB_END 0xF7FF
/*
* HCGROM
* - 126 alpha numeric characters 8x16
*/
#define HCGROM_START 0x02
#define HCGROM_END 0x7F
/*
* CGRAM
* - 4 user-defined characters 16x16
* - address range 0x0000 - 0x0006
*/
#define CGRAM_1 0x0000 /* char #1 */
#define CGRAM_2 0x0002 /* char #2 */
#define CGRAM_3 0x0004 /* char #3 */
#define CGRAM_4 0x0006 /* char #4 */
/*
* DDRAM
* - 64x2 bytes
* - 16 characters (16x16) or 32 characters (8x16) by 4 lines
* - only 2 lines can be displayed at a time
*/
#define ADDR_LINE_1 0x80 /* line #1 (0x80 - 0x8F) */
#define ADDR_LINE_2 0x90 /* line #2 (0x90 - 0x9F) */
#define ADDR_LINE_3 0xA0 /* line #3 (0xA0 - 0xAF) */
#define ADDR_LINE_4 0xB0 /* line #4 (0xB0 - 0xBF) */
/*
* GDRAM
* - x: 0-15 banks with 16 dots each (MSB/LSB)
* - y: 0-63 rows
*/
/* ************************************************************************
* SPI
* ************************************************************************ */
/*
* start byte for SPI
* - for synchronizing and selecting RW & RS
*/
#define START_BYTE 0b11111000 /* start byte */
#define FLAG_WRITE 0b00000000 /* write mode */
#define FLAG_READ 0b00000100 /* read mode (not supported) */
#define FLAG_CMD 0b00000000 /* command mode */
#define FLAG_DATA 0b00000010 /* data mode */
/* ************************************************************************
* basic instruction set
* ************************************************************************ */
/*
* clear display (DDRAM)
* - 1 byte cmd
* - fill with spaces and go to first character in first line
* - exec time: 1.6ms
*/
#define CMD_CLEAR 0b00000001 /* clear display */
/*
* return home (DDRAM)
* - 1 byte cmd
* - go to first character in first line
* - exec time: 72µs
*/
#define CMD_HOME 0b00000010 /* return home */
/*
* set entry mode
* - 1 byte cmd
* - set cursor movement and display shifting
* - exec time: 72µs
*/
#define CMD_ENTRY_MODE 0b00000100 /* set entry mode */
#define FLAG_DECREASE 0b00000000 /* decrease address (move left) */
#define FLAG_INCREASE 0b00000010 /* increase address (move right) */
#define FLAG_DISPLAY_NOSHIFT 0b00000000 /* auto shifting off */
#define FLAG_DISPLAY_SHIFT 0b00000001 /* auto shifting on */
/*
* display status
* - 1 byte cmd
* - exec time: 72µs
*/
#define CMD_DISPLAY 0b00001000 /* display status */
#define FLAG_DISPLAY_OFF 0b00000000 /* display off */
#define FLAG_DISPLAY_ON 0b00000100 /* display on */
#define FLAG_CURSOR_OFF 0b00000000 /* cursor off */
#define FLAG_CURSOR_ON 0b00000010 /* cursor on */
#define FLAG_BLINK_OFF 0b00000000 /* blinking off */
#define FLAG_BLINK_ON 0b00000001 /* blinking on */
/*
* cursor and display shift control
* - 1 byte cmd
* - exec time: 72µs
*/
#define CMD_CURSOR 0b00010000 /* cursor control */
#define FLAG_SHIFT_CURSOR 0b00000000 /* shift cursor */
#define FLAG_SHIFT_DISPLAY 0b00001000 /* shift display */
#define FLAG_SHIFT_LEFT 0b00000000 /* shift left */
#define FLAG_SHIFT_RIGHT 0b00000100 /* shift right */
/*
* function set
* - 1 byte cmd
* - exec time: 72µs
* - can't set interface and instruction set at once
*/
#define CMD_FUNCTION_SET 0b00100000 /* function set */
#define FLAG_INTERFACE_4BIT 0b00000000 /* enable 4 bit data interface */
#define FLAG_INTERFACE_8BIT 0b00010000 /* enable 8 bit data interface */
#define FLAG_CMD_BASIC 0b00000000 /* basic instruction set */
#define FLAG_CMD_EXT 0b00000100 /* extended instruction set */
/*
* set CGRAM address
* - 1 byte cmd
* - exec time: 72µs
* - valid range: 0x00 - 0x3F
*/
#define CMD_SET_CGRAM_ADDR 0b01000000 /* set CGRAM address */
/*
* set DDRAM address
* - 1 byte cmd
* - exec time: 72µs
*/
#define CMD_SET_DDRAM_ADDR 0b10000000 /* set DDRAM address */
/* ************************************************************************
* extended instruction set
* ************************************************************************ */
/*
* stand-by mode
* - 1 byte cmd
* - any other new command disables stand-by
* - exec time: 72µs
*/
#define CMD_STAND_BY 0b00000001 /* enter stand-by */
/*
* vertical scroll or RAM address select
* - 1 byte cmd
* - exec time: 72µs
*/
#define CMD_SELECT 0b00000010 /* address select */
#define FLAG_CGRAM 0b00000000 /* CGRAM address */
#define FLAG_VSCROLL 0b00000001 /* vertical scroll address */
/*
* reverse
* - 1 byte cmd
* - another reverse command toggles the reverse condition
* - exec time: 72µs
*/
#define CMD_REVERSE 0b00000100 /* reverse */
#define FLAG_LINE_1 0b00000000 /* line #1 */
#define FLAG_LINE_2 0b00000001 /* line #2 */
#define FLAG_LINE_3 0b00000010 /* line #3 */
#define FLAG_LINE_4 0b00000011 /* line #4 */
/*
* extended function set
* - 1 byte cmd
* - exec time: 72µs
* - can't set interface, instruction set or graphic display at once
*/
#define CMD_EXT_FUNC_SET 0b00100000 /* extended function set */
#define FLAG_INTERFACE_4BIT 0b00000000 /* enable 4 bit data interface */
#define FLAG_INTERFACE_8BIT 0b00010000 /* enable 8 bit data interface */
#define FLAG_CMD_BASIC 0b00000000 /* basic instruction set */
#define FLAG_CMD_EXT 0b00000100 /* extended instruction set */
#define FLAG_GFX_OFF 0b00000000 /* graphic display off */
#define FLAG_GFX_ON 0b00000010 /* graphic display on */
/*
* set vertical scroll address
* - 1 byte cmd
* - exec time: 72µs
* - 6 bits
*/
#define CMD_SET_SCROLL_ADDR 0b01000000 /* set scroll address */
/*
* set graphic RAM address
* - 1 byte cmd
* - exec time: 72µs
* - 2 byte command
*/
#define CMD_SET_GDRAM_ADDR 0b10000000 /* set GDRAM address */
/* byte #1: vertical address (7 bits) */
/* byte #2: horizontal address / bank (4 bits) */
/* ************************************************************************
* EOF
* ************************************************************************ */