Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1687 | - | 1 | |
2 | /****************************************************************/ |
||
3 | /* */ |
||
4 | /* NG-Video 5,8GHz */ |
||
5 | /* */ |
||
6 | /* Copyright (C) 2011 - gebad */ |
||
7 | /* */ |
||
8 | /* This code is distributed under the GNU Public License */ |
||
9 | /* which can be found at http://www.gnu.org/licenses/gpl.txt */ |
||
10 | /* */ |
||
11 | /* using DOGM-Library 1.0. */ |
||
12 | /* Copyright (C) 2010-averyfarwaydate Luca Bertoncello */ |
||
13 | /* Hartigstrasse, 12 - 01127 Dresden Deutschland */ |
||
14 | /* E-Mail: lucabert@lucabert.de, lucabert@lucabert.com */ |
||
15 | /* http://www.lucabert.de/ http://www.lucabert.com/ */ |
||
16 | /****************************************************************/ |
||
17 | |||
18 | #include <util/delay.h> |
||
19 | |||
20 | #include "config.h" |
||
21 | #include "dogm.h" |
||
22 | #include <avr/pgmspace.h> |
||
23 | #include <string.h> |
||
24 | |||
25 | // Instruktionen mit ST7036 4 Bit Mode im "Extension mode" |
||
26 | #define CLEAR_DISPLAY 0b00000001 |
||
27 | #define FUNCTION_SET_INIT_0 0b00110011 // 0x30 & 0x30 als nibble |
||
28 | #define FUNCTION_SET_INIT_1 0b00110010 // 0x30 & 0x20 als nibble |
||
29 | #define FUNCTION_SET_INIT_2 0b00101001 // 0x29 4-bit, 2 Zeilen, kein DoubleHeight, InstructionTable1 |
||
30 | #define INSTRUCTION_Table_0 0b00101000 // Instruction table 0 |
||
31 | #define INSTRUCTION_Table_1 0b00101001 // Instruction table 1 |
||
32 | #define SET_CGRAM 0b01000000 // für user defined Char |
||
33 | #define BIAS_SET 0b00010101 // table 1 DB3=Bias 1/4, DB0=3 Zeilen 0b00011101 |
||
34 | #define FOLLOWER_CONTROL 0b01101110 // nach Datenblattbsp. 3,3V DOGM bei 5V 0b01101100 |
||
35 | #define CONTRAST_SET 0b01110000 // Kontrastwert Bit3 bis Bit0 |
||
36 | #define POWER_CONTRAST 0b01010100 // Bit1 und Bit0 entspricht Kontrastwert Bit5 und Bit4 3,3V 0b0101 0100 5V 0b0101 0000 |
||
37 | #define DISPLAY_ON 0b00001100 |
||
38 | #define ENTRY_MODE 0b00000110 // Cursor Auto-Increment |
||
39 | #define SET_DDRAM_ADDR 0b10000000 // Bit7 bis Bit0 Adresse |
||
40 | #define BS 3 // 0 - 1/5 bias // 1 - 1/4 bias |
||
41 | #define RAB1 1 // select follower amplified ratio |
||
42 | #define BON 2 // set booster circuit on/off bei Power_Contrast |
||
43 | |||
44 | #define lcdSetEnable() LCD_E_PORT |= (1<<LCD_ENABLE); |
||
45 | #define lcdClearEnable() LCD_E_PORT &= ~(1<<LCD_ENABLE); |
||
46 | #define lcdSetRegSelect() LCD_RS_PORT |= (1<<LCD_REGSELECT) |
||
47 | #define lcdClearRegSelect() LCD_RS_PORT &= ~(1<<LCD_REGSELECT) |
||
48 | |||
49 | uint8_t CursorPos; // ersetzt lesen der aktuellen LCD-CursorPosition |
||
50 | |||
51 | /************************************************************************************/ |
||
52 | /* sendet ein Nibble (4 Bit) zum LCD-Controller */ |
||
53 | /* Parameter: */ |
||
54 | /* char data :Byte */ |
||
55 | /* */ |
||
56 | /************************************************************************************/ |
||
57 | void lcdSendNibble(char data) |
||
58 | { |
||
59 | LCD_DATA_PORT |= (data & 0x0f); |
||
60 | LCD_DATA_PORT &= (data | 0xf0); |
||
61 | lcdSetEnable(); |
||
62 | _delay_us(2); |
||
63 | lcdClearEnable(); |
||
64 | _delay_us(30); // nach Datenblatt > 26,3µs |
||
65 | } |
||
66 | |||
67 | /************************************************************************************/ |
||
68 | /* sendet 8 Bit (2 Nibble) zum LCD-Controller */ |
||
69 | /* Parameter: */ |
||
70 | /* char data :Byte */ |
||
71 | /* */ |
||
72 | /************************************************************************************/ |
||
73 | void lcdSendByte(char data) |
||
74 | { |
||
75 | lcdSendNibble(data>>4); |
||
76 | lcdSendNibble(data); |
||
77 | } |
||
78 | |||
79 | /************************************************************************************/ |
||
80 | /* sendet instruction zum LCD-Controller */ |
||
81 | /* Parameter: */ |
||
82 | /* char instruction :Byte */ |
||
83 | /* */ |
||
84 | /************************************************************************************/ |
||
85 | void lcdSendInstruction(char instruction) |
||
86 | { |
||
87 | lcdClearRegSelect(); // LCD-RS für Instruktionen |
||
88 | lcdSendByte(instruction); |
||
89 | } |
||
90 | |||
91 | /************************************************************************************/ |
||
92 | /* sendet ein Zeichen zum LCD-Display */ |
||
93 | /* Parameter: */ |
||
94 | /* char c :Zeichen */ |
||
95 | /* */ |
||
96 | /************************************************************************************/ |
||
97 | void lcdSendC(char c) |
||
98 | { |
||
99 | lcdSetRegSelect(); // LCD-RS für Daten |
||
100 | lcdSendByte(c); |
||
101 | } |
||
102 | |||
103 | /************************************************************************************/ |
||
104 | /* sendet ein Zeichen zum LCD-Display */ |
||
105 | /* Parameter: */ |
||
106 | /* char c :Zeichen */ |
||
107 | /* */ |
||
108 | /************************************************************************************/ |
||
109 | void lcdPutc(char c) |
||
110 | { |
||
111 | lcdSendC(c); |
||
112 | CursorPos++; |
||
113 | if (CursorPos >= (LCD_LINES * LCD_COLS)) CursorPos = 0; |
||
114 | } |
||
115 | |||
116 | /************************************************************************************/ |
||
117 | /* sendet einen String zum LCD-Display */ |
||
118 | /* Parameter: */ |
||
119 | /* char *str :Zeichenkette */ |
||
120 | /* */ |
||
121 | /************************************************************************************/ |
||
122 | void lcdPuts(char *str) |
||
123 | { uint8_t pos = CursorPos / LCD_COLS; |
||
124 | |||
125 | while (*str) { |
||
126 | if (*str == '\n') { |
||
127 | if (pos >= LCD_LINES) |
||
128 | pos = 0; |
||
129 | else |
||
130 | pos++; |
||
131 | lcdGotoXY(0, pos); |
||
132 | } |
||
133 | else |
||
134 | lcdPutc(*str); |
||
135 | str++; |
||
136 | } |
||
137 | } |
||
138 | |||
139 | /************************************************************************************/ |
||
140 | /* stellt eine String mittig auf Display dar */ |
||
141 | /* Parameter: */ |
||
142 | /* char *str : darzustellende Zeichenkette */ |
||
143 | /* uint8_t zle : Display-Zeile */ |
||
144 | /* */ |
||
145 | /************************************************************************************/ |
||
146 | void lcdPutStrMid(char *str, uint8_t zle) |
||
147 | { int8_t x; |
||
148 | |||
149 | lcdClearLine(zle); |
||
150 | x = (LCD_COLS - strlen(str))/2; // Array-String mittig schreiben |
||
151 | lcdGotoXY(x,zle); |
||
152 | lcdPuts(str); |
||
153 | } |
||
154 | |||
155 | /************************************************************************/ |
||
156 | /* Definieren eines Sonderzeichen */ |
||
157 | /* Parameter: */ |
||
158 | /* uint8_t lcd_addr : Adresse, 1.Adresse 0 */ |
||
159 | /* char *lcd_zeichen: Zeiger auf das 1. Byte der Zeichendefinition */ |
||
160 | /* */ |
||
161 | /************************************************************************/ |
||
162 | void lcdWriteCGRAM(uint8_t lcd_addr, char *lcdChr) |
||
163 | { int8_t i; |
||
164 | |||
165 | lcdSendInstruction(INSTRUCTION_Table_0); |
||
166 | for(i = 0; i < 8; i++) |
||
167 | { |
||
168 | lcdSendInstruction(SET_CGRAM | (lcd_addr * 8 + i)); // CG RAM Adresse |
||
169 | //lcdPutc(lcdChr[i]); // Data Write 8x Pixelzeile |
||
170 | lcdPutc(pgm_read_byte(&lcdChr[i])); // array im Flash |
||
171 | } |
||
172 | lcdSendInstruction(INSTRUCTION_Table_1); |
||
173 | } |
||
174 | |||
175 | /************************************************************************/ |
||
176 | /* Definieren von n <= 8 Sonderzeichen */ |
||
177 | /* Parameter: */ |
||
178 | /* SpecialChr_t lcdChr : Array mit Sonderzeichen */ |
||
179 | /* uint8_t quantity : Anzahl der zu übertragenen Sonderzeichen */ |
||
180 | /* */ |
||
181 | /************************************************************************/ |
||
182 | void lcdWriteCGRAM_Array(SpecialChr_t *lcdChr, uint8_t quantity) |
||
183 | { |
||
184 | for (uint8_t i = 0; i < quantity; i++) |
||
185 | lcdWriteCGRAM(i, lcdChr[i]); // Sonderzeichen in CGRAM der LCD schreiben |
||
186 | } |
||
187 | |||
188 | /************************************************************************************/ |
||
189 | /* Löscht Inhalt auf LCD-Display */ |
||
190 | /* */ |
||
191 | /************************************************************************************/ |
||
192 | void lcdClear() |
||
193 | { |
||
194 | lcdSendInstruction(CLEAR_DISPLAY); |
||
195 | CursorPos = 0; |
||
196 | _delay_ms(2); |
||
197 | } |
||
198 | |||
199 | /************************************************************************************/ |
||
200 | /* Löscht Inhalt ab Cursorposition bis Zeilenende auf LCD-Display */ |
||
201 | /* CursorPos bleibt auf ab zu löschenden Zeichen */ |
||
202 | /* */ |
||
203 | /************************************************************************************/ |
||
204 | void lcdClearEOL() |
||
205 | { uint8_t cp = CursorPos % LCD_COLS; |
||
206 | |||
207 | if (cp > 0) //falls letztes Zeichen auf letzte Spalte geschrieben, nicht nächste Zeile löschen |
||
208 | for (; cp < LCD_COLS; cp++) lcdSendC(' '); |
||
209 | lcdSendInstruction(SET_DDRAM_ADDR | CursorPos); |
||
210 | } |
||
211 | |||
212 | /************************************************************************************/ |
||
213 | /* Löscht Inhalt der angegebenen Zeile auf LCD-Display */ |
||
214 | /* CursorPos bleibt auf Zeilenanfang */ |
||
215 | /* */ |
||
216 | /************************************************************************************/ |
||
217 | void lcdClearLine(uint8_t y) |
||
218 | { |
||
219 | lcdGotoXY(0, y); |
||
220 | for (uint8_t x = 0; x < LCD_COLS; x++) lcdSendC(' '); |
||
221 | lcdSendInstruction(SET_DDRAM_ADDR | CursorPos); |
||
222 | } |
||
223 | |||
224 | /************************************************************************************/ |
||
225 | /* Setzt Kontrast auf LCD-Display */ |
||
226 | /* Parameter: */ |
||
227 | /* uint8_t contrast :Wert vo 0 bis max 63 */ |
||
228 | /* */ |
||
229 | /************************************************************************************/ |
||
230 | void lcdContrast(uint8_t dogm, uint8_t contrast) |
||
231 | { uint8_t power_contrast = POWER_CONTRAST; |
||
232 | |||
233 | if(dogm == DOGM5V) { |
||
234 | power_contrast &= ~(1<<BON); |
||
235 | } |
||
236 | lcdSendInstruction(INSTRUCTION_Table_1); |
||
237 | lcdSendInstruction(CONTRAST_SET | (contrast & 0x0F)); |
||
238 | lcdSendInstruction(power_contrast | ((contrast>>4) & 0x03)); |
||
239 | } |
||
240 | |||
241 | //***********************************************************************************/ |
||
242 | /* Setzt setzt den Cursor zur Position x/y */ |
||
243 | /* Parameter: */ |
||
244 | /* uint8_t x, :Position Spalte */ |
||
245 | /* uint8_t y, :Position Zeile */ |
||
246 | /* */ |
||
247 | /************************************************************************************/ |
||
248 | void lcdGotoXY(uint8_t x, uint8_t y) |
||
249 | { |
||
250 | if(x > LCD_COLS) x = 0; |
||
251 | if(y > LCD_LINES) y = 0; |
||
252 | CursorPos = y * LCD_COLS + x; |
||
253 | lcdSendInstruction(SET_DDRAM_ADDR | CursorPos); |
||
254 | } |
||
255 | |||
256 | /************************************************************************************/ |
||
257 | /* Initialisiert den LCD-Controller und der Atmega-Ausgänge */ |
||
258 | /* Parameter: */ |
||
259 | /* uint8_t dogm :0=3,3V oder 1=5V DOGM */ |
||
260 | /* uint8_t contrast :Wert vo 0 bis max 63 */ |
||
261 | /* uint8_t cursor :Darstellung des Cursors ein oder 0 aus */ |
||
262 | /* uint8_t blink :Cursor blinken, 0 kein blinken */ |
||
263 | /* */ |
||
264 | /************************************************************************************/ |
||
265 | void lcdInit(uint8_t dogm, uint8_t contrast, uint8_t cursor, uint8_t blink) |
||
266 | { uint8_t bias_set = BIAS_SET; |
||
267 | uint8_t follower_ctrl = FOLLOWER_CONTROL; |
||
268 | uint8_t power_contrast = POWER_CONTRAST; |
||
269 | |||
270 | LCD_BACKLIGHT_DDR |= (1<<LCD_BACKLIGHT); |
||
271 | LCD_E_DDR |= (1<<LCD_ENABLE); |
||
272 | LCD_RS_DDR |= (1<<LCD_REGSELECT); |
||
273 | LCD_DATA_DDR |= (1<<LCD_DATA7) | (1<<LCD_DATA6) | (1<<LCD_DATA5) | (1<<LCD_DATA4); |
||
274 | |||
275 | lcdClearEnable(); |
||
276 | _delay_ms(40); // lt. Datenblatt muss > 40ms nach Power On or ext. Reset |
||
277 | |||
278 | if(dogm == DOGM5V) { |
||
279 | follower_ctrl &= ~(1<<RAB1); |
||
280 | bias_set |= (1 << BS); |
||
281 | power_contrast &= ~(1<<BON); |
||
282 | } |
||
283 | |||
284 | //Initialisierung für DOGM (mit ST7036) 4 Bit Mode |
||
285 | lcdClearRegSelect(); // LCD-RS für Instruktionen |
||
286 | lcdSendNibble(FUNCTION_SET_INIT_0>>4); |
||
287 | _delay_ms(2); // lt. Datenblatt muss > 1,6ms Pause nach ersten Nibble |
||
288 | lcdSendNibble(FUNCTION_SET_INIT_0); |
||
289 | lcdSendInstruction(FUNCTION_SET_INIT_1); |
||
290 | lcdSendInstruction(FUNCTION_SET_INIT_2); |
||
291 | lcdSendInstruction(bias_set); |
||
292 | lcdSendInstruction(CONTRAST_SET | (contrast & 0x0F)); |
||
293 | lcdSendInstruction(power_contrast | ((contrast>>4) & 0x03)); |
||
294 | lcdSendInstruction(follower_ctrl); |
||
295 | lcdSendInstruction(INSTRUCTION_Table_0); |
||
296 | lcdSendInstruction(DISPLAY_ON | (cursor & 0x01) << 1 | (blink & 0x01)); |
||
297 | lcdClear(); |
||
298 | lcdSendInstruction(ENTRY_MODE); |
||
299 | } |