1 | //Includes for OLED
|
2 | #include "oled_s6e63d6_drv_8bit.h"
|
3 | #include "font.h"
|
4 | #include <avr/io.h>
|
5 | #include <util/delay.h>
|
6 |
|
7 | //Defines for OLED Steuerpins
|
8 | #define OLED_DDR DDRJ
|
9 | #define OLED_PORT PORTJ
|
10 | #define OLED_CS PJ0
|
11 | #define OLED_RS PJ2
|
12 | #define OLED_WRB PJ1
|
13 | #define OLED_RDB PJ3
|
14 | #define OLED_RST PJ4
|
15 | #define OLED_SPG PJ5
|
16 | //#define OLED_EN //liegt auf GND
|
17 |
|
18 | //Defines für OLED Datenpins
|
19 | #define DATA_DDR DDRC
|
20 | #define DATA_PORT PORTC
|
21 |
|
22 | //Defines für Zeichengröße
|
23 | //#define std_y_size 10
|
24 | //#define std_x_size 8
|
25 |
|
26 | #define std_y_size 11
|
27 | #define std_x_size 8
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | //****************************************************//
|
34 | // 8bit Parallel Index und Parameter Write Routinen
|
35 | // 8bit Modus Init für Ports und OLED
|
36 | // 8bit mit 262k Farben
|
37 | // D1-D8 => DATA_PORT
|
38 | // ID_MIB = low ==>8080 MODE
|
39 | //****************************************************//
|
40 |
|
41 |
|
42 | void oled_write_index_8bit(unsigned char index)
|
43 | {
|
44 |
|
45 | //Indexdatenausgabe an OLED im 8bit Modus an D8-D1
|
46 | //Daten an Bus anlegen
|
47 | //
|
48 | //RDB = high (heißt off) keine Readoperation
|
49 | //RS = low für Indexdatenübertragung (Registersetzen in welches die Parameter eingetragen werden sollen)
|
50 | //CS = low OLED Controller wird ausgewählt
|
51 | //WRB Impuls von low nach high damit der OLED Controller die anliegenden Daten übernimmt
|
52 | //CS = high OLED Controller wird deselectiert ("losgelassen")
|
53 |
|
54 | DATA_PORT = index; //lege indexdaten an
|
55 |
|
56 | OLED_PORT |= (1<<OLED_RDB); //Read off
|
57 | OLED_PORT &= ~(1<<OLED_RS); //Index write select
|
58 | OLED_PORT &= ~(1<<OLED_CS); // Chip select
|
59 | OLED_PORT &= ~(1<<OLED_WRB); //Übernehme Indexdaten (Write index)
|
60 | OLED_PORT |= (1<<OLED_WRB);
|
61 | OLED_PORT |= (1<<OLED_CS); // Chip disselect
|
62 |
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 | void oled_write_para_8bit(unsigned int para)
|
68 | {
|
69 |
|
70 | //Parameterdatenausgabe an OLED im 8bit Modus an D8-D1
|
71 | //Da die Parameter 16bit breit sind un der Datenbus nur 8bit wird diese Übertragung in
|
72 | //zwei aufeinander folgenden Schritten bewältigt
|
73 | //
|
74 | //RDB = high (heißt off) keine Readoperation
|
75 | //
|
76 | //1. Paket:
|
77 | //Erster Teil der Daten an Bus anlegen
|
78 | //RS = high für Parameterdatenübertragung
|
79 | //CS = low OLED Controller wird ausgewählt
|
80 | //WRB Impuls von low nach high damit der OLED Controller die anliegenden Daten übernimmt
|
81 | //CS = high OLED Controller wird deselectiert ("losgelassen")
|
82 | //
|
83 | //2.Paket:
|
84 | //Zweiter Teil der Daten an Bus anlegen
|
85 | //RS = high für Parameterdatenübertragung
|
86 | //CS = low OLED Controller wird ausgewählt
|
87 | //WRB Impuls von low nach high damit der OLED Controller die anliegenden Daten übernimmt
|
88 | //CS = high OLED Controller wird deselectiert ("losgelassen")
|
89 |
|
90 | OLED_PORT |= (1<<OLED_RDB); //read off
|
91 |
|
92 | //1. Paket --> MSB
|
93 | DATA_PORT = para >> 8;
|
94 | OLED_PORT |= (1<<OLED_RS);
|
95 | OLED_PORT &= ~(1<<OLED_CS);
|
96 | OLED_PORT &= ~(1<<OLED_WRB); //Übernehme 1. Paket Parameterdaten (Write index)
|
97 | OLED_PORT |= (1<<OLED_WRB);
|
98 | OLED_PORT |= (1<<OLED_CS);
|
99 |
|
100 |
|
101 | //2. Paket --> LSB
|
102 | DATA_PORT = para;
|
103 | OLED_PORT |= (1<<OLED_RS);
|
104 | OLED_PORT &= ~(1<<OLED_CS);
|
105 | OLED_PORT &= ~(1<<OLED_WRB); //Übernehme 2. Paket Parameterdaten (Write index)
|
106 | OLED_PORT |= (1<<OLED_WRB);
|
107 | OLED_PORT |= (1<<OLED_CS);
|
108 |
|
109 |
|
110 | }
|
111 |
|
112 |
|
113 | //Reset Operation durchführen
|
114 | void oled_reset(void)
|
115 | {
|
116 |
|
117 | OLED_PORT &= ~(1<<OLED_RST);
|
118 | _delay_us(10); //Auchtung Delay Routine Compiler abhängig
|
119 | OLED_PORT |= (1<<OLED_RST);
|
120 |
|
121 | }
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | //OLED Versorgungsspannungs Treiber einschalten
|
127 | void oled_voltage_on(void)
|
128 | {
|
129 |
|
130 | //OLED_PORT |= (1<<OLED_SPG); /*NCP einschalten (Wichtig vor Init sonst OLED Tot*/
|
131 |
|
132 | }
|
133 |
|
134 |
|
135 |
|
136 | //Init im hoizontalen Betrieb (Lage des OLED)
|
137 | //Index_out(0x03);
|
138 | //Horizontal:
|
139 | //Parameter_out(0x4120);
|
140 | //links:
|
141 | //Parameter_out(0x4121);
|
142 | //rechts:
|
143 | //Parameter_out(0x4111);
|
144 | //Port und OLED Controller Init Routine
|
145 | void oled_init_parallel_8bit_80Mode(void)
|
146 | {
|
147 |
|
148 | //CONTROL PORT INIT
|
149 | OLED_DDR |= (1<<OLED_CS) | (1<<OLED_RS) | (1<<OLED_WRB) | (1<<OLED_RDB) | (1<<OLED_RST) | (1<<OLED_SPG); /**/
|
150 | OLED_PORT |= (1<<OLED_CS) | (1<<OLED_RS) | (1<<OLED_WRB) | (1<<OLED_RDB) | (1<<OLED_RST);
|
151 | OLED_PORT &= ~(1<<OLED_SPG); /**/
|
152 |
|
153 | //DATA PORT INIT
|
154 | DATA_DDR = 0xFF;
|
155 | DATA_PORT = 0x00;
|
156 |
|
157 |
|
158 |
|
159 | //RESET OLED
|
160 | oled_reset();
|
161 |
|
162 |
|
163 | //OLED REGISTER INIT
|
164 | //1. entry mode -> 8bit
|
165 | //2. stand by -> off
|
166 | //3. disp control 1 -> off
|
167 | //4. oss control -> maximum
|
168 |
|
169 | oled_write_index_8bit(0x24); //8bit Mode
|
170 |
|
171 | oled_write_index_8bit(0x02); //RGB Interface Control
|
172 | oled_write_para_8bit(0x0000); //CPU Interface (Internal Clock)
|
173 |
|
174 | oled_write_index_8bit(0x18); //Osscillator Control
|
175 | oled_write_para_8bit(0x0028); //max. Frequence
|
176 |
|
177 | oled_write_index_8bit(0x03); //Entry Mode (4110 für h = inc, v = dec)
|
178 | oled_write_para_8bit(0x4130); //CLS = 0; MDT1:0 = 00; BGR = 0; SS = 1; ID1:0 = 10; AM = 0; 262K Colour, Horizontal Update AM = 0 -> (H = increment,V = increment)
|
179 |
|
180 | oled_write_index_8bit(0x10); //Standby
|
181 | oled_write_para_8bit(0x0000); //Standby off
|
182 |
|
183 | oled_write_index_8bit(0x05); //Display Control 1
|
184 | oled_write_para_8bit(0x0000); //Display off
|
185 |
|
186 | oled_write_index_8bit(0x18); //Oscillator Control
|
187 | oled_write_para_8bit(0x0028); //Osc. auf maximum 80Hz
|
188 |
|
189 | //OLED GAMMA SETTING
|
190 | //1. gamma top_bottom control r
|
191 | //2. gamma top_bottom control g
|
192 | //3. gamma top_bottom control b
|
193 | //4. gamma control r 1-2
|
194 | //5. gamma control r 3-4
|
195 | //6. gamma control g 1-2
|
196 | //7. gamma control g 3-4
|
197 | //8. gamma control b 1-2
|
198 | //9. gamma control b 3-4
|
199 |
|
200 | oled_write_index_8bit(0x70); //Gamma Top Bottom Control R
|
201 | oled_write_para_8bit(0x2580); //
|
202 |
|
203 | oled_write_index_8bit(0x71); //Gamma Top Bottom Control G
|
204 | oled_write_para_8bit(0x2780); //
|
205 |
|
206 | oled_write_index_8bit(0x72); //Gamma Top Bottom Control B
|
207 | oled_write_para_8bit(0x3380); //
|
208 |
|
209 | oled_write_index_8bit(0x73); //Gamma Control R 1/2
|
210 | oled_write_para_8bit(0x1D18); //
|
211 |
|
212 | oled_write_index_8bit(0x74); //Gamma Control R 3/4
|
213 | oled_write_para_8bit(0x1F11); //
|
214 |
|
215 | oled_write_index_8bit(0x75); //Gamma Control G 1/2
|
216 | oled_write_para_8bit(0x2419); //
|
217 |
|
218 | oled_write_index_8bit(0x76); //Gamma Control G 3/4
|
219 | oled_write_para_8bit(0x1A14); //
|
220 |
|
221 | oled_write_index_8bit(0x77); //Gamma Control B 1/2
|
222 | oled_write_para_8bit(0x211A); //
|
223 |
|
224 | oled_write_index_8bit(0x78); //Gamma Control B 3/4
|
225 | oled_write_para_8bit(0x2013); //
|
226 |
|
227 | //FINAL SETTINGS
|
228 | //1. disp control 1 -> on
|
229 | //2. OLED POWER ON (no setting (NCP CHIP))
|
230 |
|
231 | oled_write_index_8bit(0x05); //Display Control 1
|
232 | oled_write_para_8bit(0x0001); //Display on
|
233 |
|
234 | oled_voltage_on();
|
235 |
|
236 | _delay_ms(10);
|
237 |
|
238 | }
|
239 |
|
240 |
|
241 |
|
242 | //****************************************************//
|
243 | // 8bit Pixel Write Routinen
|
244 | // 8bit mit 262k Farben
|
245 | // D3-D8 => DATA_PORT
|
246 | //****************************************************//
|
247 |
|
248 |
|
249 | void oled_pixel_write(unsigned char r, unsigned char g, unsigned char b)
|
250 | {
|
251 |
|
252 | //Pixeldatenausgabe im 8bit Modus an OLED für 262k Colors an D8-D3
|
253 | //dadurch findet RGB-Datenübertragung in 3 Transmissions statt zu je
|
254 | //6bit für jede Farbe (R,G,B).
|
255 | //Jede Farbe liegt (weil "einfach") als eigene Var. vor.
|
256 |
|
257 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
258 | //!!Achtung vor dem Schreiben in den GRAM (sprich verwenden der Pixelfunktion) muss !!
|
259 | //!!der GRAM_Write Befehl ausgeführt werden d.H. !!
|
260 | //!! oled_write_index_8bit(0x22); !!
|
261 | //!!und nach dem alle Pixel in den GRAM des OLED Controllers geschrieben sind muss !!
|
262 | //!!dem Controller mit !!
|
263 | //!! oled_write_index_8bit(0x00); //Beendet Memory write and read !!
|
264 | //!!mitgeteilt werden das das schreiben von Daten in den GRAM abgeschlossen ist !!
|
265 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
266 |
|
267 | OLED_PORT |= (1<<OLED_RDB); //read off
|
268 |
|
269 | OLED_PORT |= (1<<OLED_RS); //GRAM write
|
270 |
|
271 | DATA_PORT = r<<2; //Daten anlegen
|
272 | OLED_PORT &= ~(1<<OLED_CS); //AMOLED Driver Chip selektieren
|
273 | OLED_PORT &= ~(1<<OLED_WRB); //Übernehme R-Daten
|
274 | OLED_PORT |= (1<<OLED_WRB); // Ende Write
|
275 | OLED_PORT |= (1<<OLED_CS); // AMOLED Driver Chip "loslassen"
|
276 |
|
277 | DATA_PORT = g<<2;
|
278 | OLED_PORT &= ~(1<<OLED_CS);
|
279 | OLED_PORT &= ~(1<<OLED_WRB); //Übernehme G-Daten
|
280 | OLED_PORT |= (1<<OLED_WRB);
|
281 | OLED_PORT |= (1<<OLED_CS);
|
282 |
|
283 | DATA_PORT = b<<2;
|
284 | OLED_PORT &= ~(1<<OLED_CS);
|
285 | OLED_PORT &= ~(1<<OLED_WRB); //Übernehme B-Daten
|
286 | OLED_PORT |= (1<<OLED_WRB);
|
287 | OLED_PORT |= (1<<OLED_CS);
|
288 |
|
289 | }
|
290 |
|
291 |
|
292 |
|
293 | void oled_set_address(unsigned int x, unsigned int y)
|
294 | {
|
295 |
|
296 | oled_write_index_8bit(0x20); //Setzte x start position
|
297 | oled_write_para_8bit(x);
|
298 |
|
299 | oled_write_index_8bit(0x21); //Setzte y start position
|
300 | oled_write_para_8bit(y);
|
301 |
|
302 | //Vorbereiten auf Pixel write
|
303 | //oled_write_index_8bit(0x22); //GRAM für Grafikdaten vorbereiten
|
304 |
|
305 | }
|
306 |
|
307 |
|
308 |
|
309 | void oled_scroll_screen(unsigned int ssa, unsigned int sea, unsigned int sst)
|
310 | {
|
311 | //Automatisches vertikales Scrollen der Anzeige (siehe Datenblatt für Werte/Funktion)
|
312 |
|
313 | oled_write_index_8bit(0x30); //Setzte vertikal scroll start address position
|
314 | oled_write_para_8bit(ssa);
|
315 |
|
316 | oled_write_index_8bit(0x31); //Setzte vertikal scroll end address position
|
317 | oled_write_para_8bit(sea);
|
318 |
|
319 |
|
320 | oled_write_index_8bit(0x32); //Setzte der Scroll Schritte
|
321 | oled_write_para_8bit(sst);
|
322 |
|
323 | }
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | void oled_draw_fill_rec(unsigned int vsa, unsigned int vea, unsigned char hsa, unsigned char hea, unsigned char r, unsigned char g, unsigned char b)
|
329 | {
|
330 |
|
331 | //Funktion zum eingrenzen eines viereckigen Rahmens und Füllen dieses Rahmens mit einer Farbe.
|
332 | //Über VSA,VEA und HSA,HEA wird das Viereck "im OLED Controller" bestimmt und mit der Farbe aus r,g,b gefüllt.
|
333 |
|
334 |
|
335 | //Setze Rahmen
|
336 | oled_write_index_8bit(0x35); //Setzte vertikal start address position
|
337 | oled_write_para_8bit(vsa);
|
338 |
|
339 | oled_write_index_8bit(0x36); //Setzte vertikal end address position
|
340 | oled_write_para_8bit(vea);
|
341 |
|
342 |
|
343 | oled_write_index_8bit(0x37); //Setzte horizontal start und end address position
|
344 | oled_write_para_8bit((int)((int) hsa<<8) | (int)hea);
|
345 |
|
346 | //Setzen der Start Addresse um mit dem Füllen des gesetzten Recheckes zu beginnen (oben links beginnen => hsa,vsa)
|
347 | oled_write_index_8bit(0x20); //Setzte x start position
|
348 | oled_write_para_8bit(hsa);
|
349 |
|
350 | oled_write_index_8bit(0x21); //Setzte y start position
|
351 | oled_write_para_8bit(vsa);
|
352 |
|
353 | oled_write_index_8bit(0x03); //Entry Mode
|
354 | oled_write_para_8bit(0x4130);
|
355 |
|
356 | //Fülle Rechteck mit Farbe (mit Hilfe der oled_pixel_write() Funktion)
|
357 | oled_write_index_8bit(0x22); //GRAM für Grafikdaten vorbereiten
|
358 |
|
359 |
|
360 | for(unsigned long x=0;x<((unsigned long)vea-(unsigned long)vsa+1)*(unsigned long)(hea-hsa+1);x++)
|
361 | {
|
362 | oled_pixel_write(r, g, b);
|
363 | }
|
364 |
|
365 |
|
366 | oled_write_index_8bit(0X00); //OLED Controller mitteilen das das schreiben von Grafikdaten in den GRAM zu ende ist
|
367 |
|
368 | }
|
369 |
|
370 |
|
371 |
|
372 | /*
|
373 | void oled_set_rec(unsigned int vsa, unsigned int vea, unsigned char hsa, unsigned char hea)
|
374 | {
|
375 |
|
376 | //Funktion zur Erzeugung eines beschreibaren Rechteckes
|
377 |
|
378 | //Fenster Adresse
|
379 | oled_write_index_8bit(0x00); //keine GRAM Daten
|
380 | oled_write_index_8bit(0x21); //Startadresse festlegen
|
381 |
|
382 | oled_write_para_8bit(hsa); //X-Adresse
|
383 | oled_write_para_8bit(vsa); //Y-Adresse
|
384 | //1
|
385 |
|
386 | //Rahmen aufbauen
|
387 | oled_write_index_8bit(0x00);
|
388 | oled_write_index_8bit(0x23); //Setzte VEA, VSA
|
389 |
|
390 | oled_write_para_8bit(vea); //Vertikal Ende
|
391 | oled_write_para_8bit(vsa); //Vertikal Start
|
392 |
|
393 | oled_write_index_8bit(0x00);
|
394 | oled_write_index_8bit(0x24); //Setzte HEA, HSA
|
395 |
|
396 | oled_write_para_8bit(hea); //Horizontal Ende
|
397 | oled_write_para_8bit(hsa); //Horizontal Start
|
398 | //2
|
399 |
|
400 | //evtl. NOPs einbauen an 1,2
|
401 |
|
402 | }
|
403 | */
|
404 |
|
405 |
|
406 |
|
407 | void oled_set_rec(unsigned int vsa, unsigned int vea, unsigned char hsa, unsigned char hea)
|
408 | {
|
409 |
|
410 | //Funktion zur Erzeugung eines beschreibaren Rahmens/Windows
|
411 |
|
412 | //Setze Rahmen
|
413 | oled_write_index_8bit(0x35); //Setzte vertikal start address position
|
414 | oled_write_para_8bit(vsa);
|
415 |
|
416 | oled_write_index_8bit(0x36); //Setzte vertikal end address position
|
417 | oled_write_para_8bit(vea);
|
418 |
|
419 |
|
420 | oled_write_index_8bit(0x37); //Setzte horizontal start und end address position
|
421 | oled_write_para_8bit((int)((int) hsa<<8) | (int)hea);
|
422 |
|
423 | //Setzen der Start Addresse
|
424 | oled_write_index_8bit(0x20); //Setzte x start position
|
425 | oled_write_para_8bit(vsa);
|
426 |
|
427 | oled_write_index_8bit(0x21); //Setzte y start position
|
428 | oled_write_para_8bit(hsa);
|
429 |
|
430 | }
|
431 |
|
432 |
|
433 |
|
434 | void oled_draw_ascii_horizontal_at_pos(unsigned char ascii, unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b, unsigned char rb, unsigned char gb, unsigned char bb)
|
435 | {
|
436 |
|
437 | //Funktion zum Schreiben eines Zeichens in horizontaler Richtung (normale Größe) an Position x,y auf dem OLED
|
438 | //Grundstrucktur für print_string
|
439 | // _______
|
440 | // | ----> |
|
441 | // | / |
|
442 | // |_______|
|
443 | //
|
444 |
|
445 | unsigned char h = 0;
|
446 | unsigned char w = 0;
|
447 | unsigned char ch = 0;
|
448 |
|
449 | //Setze des Rahmen für ASCII Zeichen Größe
|
450 | oled_write_index_8bit(0x35); //Setzte vertikal start address position
|
451 | oled_write_para_8bit(y);
|
452 |
|
453 | oled_write_index_8bit(0x36); //Setzte vertikal end address position
|
454 | oled_write_para_8bit(y + std_x_size - 1);
|
455 |
|
456 | oled_write_index_8bit(0x37); //Setzte horizontal start und end address position
|
457 | oled_write_para_8bit((unsigned int) ((unsigned int) x<<8 ) | (unsigned int) (x + std_y_size - 1));
|
458 |
|
459 | //Setzen der Start Addresse
|
460 | oled_write_index_8bit(0x20); //Setzte x Start Position
|
461 | oled_write_para_8bit(x);
|
462 |
|
463 | oled_write_index_8bit(0x21); //Setzte y Start Position
|
464 | oled_write_para_8bit(y);
|
465 |
|
466 | //Setzen der Einstellungen um ASCII zu Zeichnen
|
467 | oled_write_index_8bit(0x03); //Entry Mode (4110 für h = inc, v = dec)
|
468 | oled_write_para_8bit(0x4131); //CLS = 0; MDT1:0 = 00; BGR = 0; SS = 1; ID1:0 = 10; AM = 1 -> (H = increment,V = decrement)
|
469 |
|
470 | //ASCII Auswahl
|
471 |
|
472 | oled_write_index_8bit(0x22);
|
473 |
|
474 | //x = 8, y = 11
|
475 | for(h = 0; h < 11; h++)
|
476 | {
|
477 |
|
478 | ch = STD_Font[ascii-32][h];
|
479 |
|
480 | for(w = 0; w < 8; w++)
|
481 | {
|
482 |
|
483 | if((ch >> w) & 0x01)
|
484 | {
|
485 | oled_pixel_write(r,g,b);
|
486 | }
|
487 | else
|
488 | {
|
489 | oled_pixel_write(rb,gb,bb);
|
490 | }
|
491 |
|
492 | }
|
493 |
|
494 | }
|
495 |
|
496 | oled_write_index_8bit(0x00);
|
497 |
|
498 | }
|
499 |
|
500 |
|
501 |
|
502 | void oled_draw_ascii_vertical_at_pos(unsigned char ascii, unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b, unsigned char rb, unsigned char gb, unsigned char bb)
|
503 | {
|
504 |
|
505 | //Funktion zu Darstellen eines Vertikalen Zeichens
|
506 | //
|
507 | // _____
|
508 | // |---->|
|
509 | // | / |
|
510 | // | / |
|
511 | // | |
|
512 | // |_____|
|
513 | //
|
514 |
|
515 | unsigned char h = 0;
|
516 | unsigned char w = 0;
|
517 | unsigned char ch = 0;
|
518 |
|
519 | //Setze des Rahmen für ASCII Zeichen Größe
|
520 | oled_write_index_8bit(0x35); //Setzte vertikal start address position
|
521 | oled_write_para_8bit(y);
|
522 |
|
523 | oled_write_index_8bit(0x36); //Setzte vertikal end address position
|
524 | oled_write_para_8bit(y + std_y_size - 1);
|
525 |
|
526 | oled_write_index_8bit(0x37); //Setzte horizontal start und end address position
|
527 | oled_write_para_8bit((unsigned int) ((unsigned int) x<<8 ) | (unsigned int) (x + std_x_size - 1));
|
528 |
|
529 | //Setzen der Start Addresse
|
530 | oled_write_index_8bit(0x20); //Setzte x Start Position
|
531 | oled_write_para_8bit(x);
|
532 |
|
533 | oled_write_index_8bit(0x21); //Setzte y Start Position
|
534 | oled_write_para_8bit(y);
|
535 |
|
536 | //Setzen der Einstellungen um ASCII zu Zeichnen
|
537 | oled_write_index_8bit(0x03); //Entry Mode (4110 für h = inc, v = dec)
|
538 | oled_write_para_8bit(0x4120);
|
539 |
|
540 | //ASCII Auswahl
|
541 |
|
542 | oled_write_index_8bit(0x22);
|
543 |
|
544 | //x = 8, y = 11
|
545 | for(h = 0; h < 11; h++)
|
546 | {
|
547 |
|
548 | ch = STD_Font[ascii-32][h];
|
549 |
|
550 | for(w = 0; w < 8; w++)
|
551 | {
|
552 |
|
553 | if((ch >> w) & 0x01)
|
554 | {
|
555 | oled_pixel_write(r,g,b);
|
556 | }
|
557 | else
|
558 | {
|
559 | oled_pixel_write(0x00,0x00,0x00);
|
560 | }
|
561 |
|
562 | }
|
563 |
|
564 | }
|
565 |
|
566 |
|
567 | oled_write_index_8bit(0x00);
|
568 |
|
569 | }
|
570 |
|
571 |
|
572 |
|
573 |
|
574 | void oled_print_h_string_at_pos(char *ascii_ptr, unsigned int x, unsigned int y, unsigned char r, unsigned char g, unsigned char b, unsigned char rb, unsigned char gb, unsigned char bb)
|
575 | {
|
576 |
|
577 | while (*ascii_ptr)
|
578 | {
|
579 |
|
580 | oled_draw_ascii_horizontal_at_pos(*ascii_ptr++ ,x ,y ,r ,g , b, rb, gb, bb);
|
581 |
|
582 | y -= 7;
|
583 |
|
584 | }
|
585 |
|
586 | }
|
587 |
|
588 |
|
589 |
|
590 | void oled_draw_picture(unsigned int vsa, unsigned int vea, unsigned char hsa, unsigned char hea, unsigned int *picture)
|
591 | {
|
592 |
|
593 | //Funktion zur Darstellung eines Bildes in horizontaler Richtung auf dem OLED
|
594 |
|
595 | //Setze Rahmen
|
596 | oled_write_index_8bit(0x35); //Setzte vertikal start address position
|
597 | oled_write_para_8bit(vsa);
|
598 |
|
599 | oled_write_index_8bit(0x36); //Setzte vertikal end address position
|
600 | oled_write_para_8bit(vea);
|
601 |
|
602 |
|
603 | oled_write_index_8bit(0x37); //Setzte horizontal start und end address position
|
604 | oled_write_para_8bit((int)((int) hsa<<8) | (int)hea);
|
605 |
|
606 | //Setzen der Start Addresse um mit dem Füllen des gesetzten Recheckes zu beginnen (oben links beginnen => hsa,vsa)
|
607 | oled_write_index_8bit(0x20); //Setzte x start position
|
608 | oled_write_para_8bit(hsa);
|
609 |
|
610 | oled_write_index_8bit(0x21); //Setzte y start position
|
611 | oled_write_para_8bit(vsa);
|
612 |
|
613 | //Setzen der Einstellungen um ASCII Horizontal zu Zeichnen
|
614 | oled_write_index_8bit(0x03); //Entry Mode (4110 für h = inc, v = dec)
|
615 | oled_write_para_8bit(0x4111); //CLS = 0; MDT1:0 = 00; BGR = 0; SS = 1; ID1:0 = 10; AM = 0; 262K Colour, Horizontal Update AM = 0 -> (H = increment,V = increment)
|
616 |
|
617 | //Fülle Rechteck mit Farbe (mit Hilfe der oled_pixel_write() Funktion)
|
618 | oled_write_index_8bit(0x22); //GRAM für Grafikdaten vorbereiten
|
619 |
|
620 | /*
|
621 | for(unsigned int x=0;x<((unsigned long)vea-(unsigned long)vsa+1)*(unsigned long)(hea-hsa+1);x++)
|
622 | {
|
623 | oled_pixel_write((unsigned int)*picture>>9, (unsigned int)*picture>>4,(unsigned int)*picture<<1);
|
624 | *picture++;
|
625 | }
|
626 | */
|
627 |
|
628 | oled_write_index_8bit(0x00); //GRAM Schreiben zu Ende
|
629 |
|
630 | }
|
631 |
|
632 |
|
633 |
|
634 | //Linie Zeichnen von vsa zu hsa
|
635 | void oled_draw_line_h(unsigned char r, unsigned char g, unsigned char b, unsigned int x, unsigned int y, unsigned int legth)
|
636 | {
|
637 |
|
638 |
|
639 | oled_write_index_8bit(0x03); //Entry Mode (4110 für h = inc, v = dec)
|
640 | oled_write_para_8bit(0x4130); //CLS = 0; MDT1:0 = 00; BGR = 0; SS = 1; ID1:0 = 10; AM = 0; 262K Colour, Horizontal Update AM = 0 -> (H = inc,V = inc)
|
641 |
|
642 | //Setze Rahmen
|
643 | oled_write_index_8bit(0x35); //Setzte vertikal start address position
|
644 | oled_write_para_8bit(0);
|
645 |
|
646 | oled_write_index_8bit(0x36); //Setzte vertikal end address position
|
647 | oled_write_para_8bit(320);
|
648 |
|
649 |
|
650 | oled_write_index_8bit(0x37); //Setzte horizontal start und end address position
|
651 | oled_write_para_8bit((int)((int) 0<<8) | (int)240);
|
652 |
|
653 | //Setzen der Start Addresse
|
654 | oled_write_index_8bit(0x20); //Setzte x start position
|
655 | oled_write_para_8bit(x);
|
656 |
|
657 | oled_write_index_8bit(0x21); //Setzte y start position
|
658 | oled_write_para_8bit(y);
|
659 |
|
660 | oled_write_index_8bit(0x22); //Beginne GRAM Daten zu schreiben
|
661 |
|
662 | for(unsigned int i=0;i<legth;i++)
|
663 | {
|
664 | oled_pixel_write(r,g,b); //Rot
|
665 | }
|
666 |
|
667 | oled_write_index_8bit(0x00); //Ende GRAM Daten schreiben
|
668 |
|
669 | }
|
670 |
|
671 |
|
672 |
|
673 | void oled_draw_line_v(unsigned char r, unsigned char g, unsigned char b, unsigned int x, unsigned y, unsigned int legth)
|
674 | {
|
675 |
|
676 | oled_write_index_8bit(0x03); //Entry Mode (4110 für h = inc, v = dec)
|
677 | oled_write_para_8bit(0x4131); //CLS = 0; MDT1:0 = 00; BGR = 0; SS = 1; ID1:0 = 10; AM = 0; 262K Colour, Vertical Update AM = 1 -> (H = inc,V = inc)
|
678 |
|
679 | //Setze Rahmen
|
680 | oled_write_index_8bit(0x35); //Setzte vertikal start address position
|
681 | oled_write_para_8bit(0);
|
682 |
|
683 | oled_write_index_8bit(0x36); //Setzte vertikal end address position
|
684 | oled_write_para_8bit(320);
|
685 |
|
686 |
|
687 | oled_write_index_8bit(0x37); //Setzte horizontal start und end address position
|
688 | oled_write_para_8bit((int)((int) 0<<8) | (int)240);
|
689 |
|
690 | //Setzen der Start Addresse
|
691 | oled_write_index_8bit(0x20); //Setzte x start position
|
692 | oled_write_para_8bit(x);
|
693 |
|
694 | oled_write_index_8bit(0x21); //Setzte y start position
|
695 | oled_write_para_8bit(y);
|
696 |
|
697 | oled_write_index_8bit(0x22); //Beginne GRAM Daten zu schreiben
|
698 |
|
699 | for(unsigned int i=0;i<legth;i++)
|
700 | {
|
701 | oled_pixel_write(r,g,b); //Rot
|
702 | }
|
703 |
|
704 | oled_write_index_8bit(0x00); //Ende GRAM Daten schreiben
|
705 |
|
706 | }
|
707 |
|
708 |
|
709 |
|
710 | void oled_clear_screen(void)
|
711 | {
|
712 |
|
713 | oled_draw_fill_rec(0,320,0,240,0x00,0x00,0x00);
|
714 |
|
715 | }
|