-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssd13xx_20x4_oled.c
414 lines (349 loc) · 8.5 KB
/
ssd13xx_20x4_oled.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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/**
* @brief Display Driver for Wide.HK OLED 20x4 I2C Text Mode Display
*
* This module implements Text output and positioning for the Wide.HK
* 20x4 OLED Character display found online at the listing shown on the
* <A HREF="https://www.ebay.com/itm/IIC-I2C-2004-20x4-Green-OLED-Module-Display-For-Arduino-PIC-AVR-ARM/162406508569"> Wide.HK Ebay Store</a>
*
* Reference:
*
* @copyright
* Copyright (C) 2017 Real Flight Systems
* @author James F Dougherty <jfd@realflightsystems.com>
*
*
*/
/**
* @defgroup display display
* @addtogroup display
* @file ssd13xx_20x4_oled.c
* @{
*/
/* device dependencies */
/* time.c */
extern void ms_delay(unsigned int usecs);
/* ssd13xx_io.c */
extern void ssd13xx_write(unsigned char addr, unsigned char data);
#define OLED_SADDR 0x3c /* SSD1311/OLED Module Slave address */
#define SSD1311_CMD_REG 0x80 /* Command Register */
#define SSD1311_DATA_REG 0x40 /* Data Register */
#define ssd13xx_command(data) \
ssd13xx_write(SSD1311_CMD_REG, (data))
#define ssd13xx_data(data) \
ssd13xx_write(SSD1311_DATA_REG, (data))
/* Library routines */
/**
* @brief display string
*
* Write null-terminated string to display. The text is output
* at the current position.
*
* @param[in] str the null terminated string to display
*/
void lcd_puts(const char *str)
{
unsigned char i = 0;
while ( str[i] ) {
ssd13xx_data(str[i]);
i++;
}
}
/**
* @brief display data
*
* Write binary data to display. The data is output
* at the current position.
*
* @param[in] data the data bytes to write to the display
* @param[in] len the number of bytes to write
*/
void lcd_write(const unsigned char *data, int len)
{
unsigned char i = 0;
while (i < len) {
ssd13xx_data(data[i]);
i++;
}
}
/**
* @brief clear screen
*
* This routine clears the display memory
*
*/
void lcd_cls(void)
{
ssd13xx_command(0x1);
}
/**
* @brief move the cursor location
*
* This routine moves the cursor to x,y location by setting the
* CGRAM output pointer (AC) to the correct DRAM address.
*
* Cursor locations are 0 based and go from: 0-3 (y) and 0-19 (x)
* 0,0 is the upper left hand corner of the display itself.
*
* @param[in] x the x position to move to
* @param[in] y the y position to move to
*/
void lcd_goto(int x, int y)
{
ssd13xx_command(0x80 + 0x20 * y + x);
}
/*
* We set the CGRAM address of a character, and then we write the bits.
*
* Each font is either 5x8 or 5x6 bits
*/
void set_cgram_addr(char addr)
{
ssd13xx_command(0x40 + addr);
}
void set_dram_addr(char addr)
{
ssd13xx_command(0x80 + addr);
}
void lcd_define_degree_symbol(void)
{
set_cgram_addr(0); /* Degrees Symbol */
ssd13xx_data(0x0c);
ssd13xx_data(0x12);
ssd13xx_data(0x12);
ssd13xx_data(0x0c);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
}
void lcd_define_minute_symbol(void)
{
set_cgram_addr(8); /* Minutes Symbol */
ssd13xx_data(0x08);
ssd13xx_data(0x10);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
}
void lcd_define_feet_symbol(void)
{
set_cgram_addr(16); /* Feet Symbol */
ssd13xx_data(0x1c);
ssd13xx_data(0x10);
ssd13xx_data(0x18);
ssd13xx_data(0x10);
ssd13xx_data(0x17);
ssd13xx_data(0x02);
ssd13xx_data(0x02);
ssd13xx_data(0x02);
}
void lcd_define_airplane_symbol(void)
{
set_cgram_addr(24); /* Airplane / Fly / Lock */
ssd13xx_data(0x04);
ssd13xx_data(0x04);
ssd13xx_data(0x0e);
ssd13xx_data(0x1f);
ssd13xx_data(0x04);
ssd13xx_data(0x04);
ssd13xx_data(0x0e);
ssd13xx_data(0x00);
}
void lcd_define_nav_symbols(void)
{
lcd_define_degree_symbol();
lcd_define_minute_symbol();
lcd_define_feet_symbol();
lcd_define_airplane_symbol();
set_cgram_addr(32); /* Sat 0 */
ssd13xx_data(0x11);
ssd13xx_data(0x1f);
ssd13xx_data(0x11);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
set_cgram_addr(40); /* Sat 1 */
ssd13xx_data(0x15);
ssd13xx_data(0x1f);
ssd13xx_data(0x15);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
set_cgram_addr(48); /* Sat 2 */
ssd13xx_data(0x15);
ssd13xx_data(0x1f);
ssd13xx_data(0x15);
ssd13xx_data(0x00);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
set_cgram_addr(56); /* Sat 3 */
ssd13xx_data(0x15);
ssd13xx_data(0x1f);
ssd13xx_data(0x15);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
ssd13xx_data(0x0e);
}
void lcd_define_vbar_symbol(void)
{
int i;
/*
* Airplane Symbol
* 00100
* 00100
* 01110
* 11111
* 00100
* 00100
* 01110
* 00000
*/
set_cgram_addr(0);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x1f);
set_cgram_addr(8);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
set_cgram_addr(16);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
set_cgram_addr(24);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
set_cgram_addr(32);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
set_cgram_addr(40);
ssd13xx_data(0x00);
ssd13xx_data(0x00);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
set_cgram_addr(48);
ssd13xx_data(0x00);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
set_cgram_addr(56);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
ssd13xx_data(0x1f);
set_dram_addr(0);
}
void ssd13xx_oled_20x4_init(void)
{
ssd13xx_command(0x80);
ssd13xx_command(0x2A); /* **** Set "RE"=1 00101010B */
ssd13xx_command(0x71);
ssd13xx_command(0xC0);
ssd13xx_command(0x00);
ssd13xx_command(0x28);
ssd13xx_command(0x08); /* **** Set Sleep Mode On */
ssd13xx_command(0x2A); /* **** Set "RE"=1 00101010B */
ssd13xx_command(0x79); /* **** Set "SD"=1 01111001B */
ssd13xx_command(0xD5);
ssd13xx_command(0x70);
ssd13xx_command(0x78); /* **** Set "SD"=0 */
//ssd13xx_command(0x08);
/* **** Set 5-dot, 3 or 4 line(0x09), 1 or 2 line(0x08) */
ssd13xx_command(0x09);
ssd13xx_command(0x06); /* **** Set Com31-->Com0 Seg0-->Seg99 */
ssd13xx_command(0x72);
ssd13xx_command(0xC0);
ssd13xx_command(0x01);
/**** Set OLED Characterization ***/
ssd13xx_command(0x2A); /* **** Set "RE"=1 */
ssd13xx_command(0x79); /* **** Set "SD"=1 */
/**** CGROM/CGRAM Management ***/
#if 0
ssd13xx_command(0x72); /* **** Set ROM */
ssd13xx_command(0x00); /* **** Set ROM A and 8 CGRAM */
#endif
ssd13xx_command(0xDC); /* **** Set ROM */
ssd13xx_command(0x00); /* **** Set ROM A and 8 CGRAM */
ssd13xx_command(0xDA); /* **** Set Seg Pins HW Config */
ssd13xx_command(0x10);
ssd13xx_command(0x81); /* **** Set Contrast */
ssd13xx_command(0xD9);
ssd13xx_command(0x8F); /* **** Set Contrast */
ssd13xx_command(0xF1);
ssd13xx_command(0xDB); /* **** Set VCOM deselect level */
ssd13xx_command(0x30); /* **** VCC x 0.83 */
ssd13xx_command(0xDC); /* *Set gpio -turn EN for 15V generator on. */
ssd13xx_command(0x03);
ssd13xx_command(0x78); /* **** Exiting Set OLED Characterization */
ssd13xx_command(0x28);
//flip display with these two lines, comment out the 0x06 write below
//ssd13xx_command(0x2A);
//ssd13xx_command(0x05); /* **** Set Entry Mode (invert) */
ssd13xx_command(0x06); /* **** Set Entry Mode */
ssd13xx_command(0x28); /* **** Set "IS"=0 , "RE" =0 /28 */
ssd13xx_command(0x01);
ssd13xx_command(0x80); /* Set DDRAM Address to 0x80 (line 1 start)*/
ms_delay(100);
ssd13xx_command(0x0C); /* **** Turn on Display */
}
void lcd_init(void)
{
ssd13xx_oled_20x4_init();
ms_delay(100);
}
void lcd_startup_banner(void)
{
lcd_goto(0,0);
lcd_cls();
}
/** @}*/