Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
962 - 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
 
23
// Instruktionen mit ST7036 4 Bit Mode im "Extension mode"
24
#define CLEAR_DISPLAY        0b00000001
25
#define FUNCTION_SET_INIT_0  0b00110011 // 0x30 & 0x30 als nibble
26
#define FUNCTION_SET_INIT_1  0b00110010 // 0x30 & 0x20 als nibble
27
#define FUNCTION_SET_INIT_2  0b00101001 // 0x29 4-bit, 2 Zeilen, kein DoubleHeight, InstructionTable1
28
#define INSTRUCTION_Table_0  0b00101000 // Instruction table 0
29
#define INSTRUCTION_Table_1  0b00101001 // Instruction table 1
30
#define SET_CGRAM                        0b01000000     // für user defined Char
31
#define BIAS_SET             0b00010101 // table 1  DB3=Bias 1/4, DB0=3 Zeilen 0b00011101
32
#define FOLLOWER_CONTROL     0b01101110 // nach Datenblattbsp. 3,3V DOGM bei 5V 0b01101100
33
#define CONTRAST_SET         0b01110000 // Kontrastwert Bit3 bis Bit0
34
#define POWER_CONTRAST           0b01010100 // Bit1 und Bit0 entspricht Kontrastwert Bit5 und Bit4 3,3V 0b0101 0100 5V 0b0101 0000
35
#define DISPLAY_ON           0b00001100
36
#define ENTRY_MODE           0b00000110 // Cursor Auto-Increment
37
#define SET_DDRAM_ADDR       0b10000000 // Bit7 bis Bit0 Adresse
38
#define BS                                       3                      // 0 - 1/5 bias // 1 - 1/4 bias
39
#define RAB1                             1                      // select follower amplified ratio
40
#define BON                                      2                      // set booster circuit on/off bei Power_Contrast
41
 
42
#define lcdSetEnable()      LCD_E_PORT  |=  (1<<LCD_ENABLE);
43
#define lcdClearEnable()    LCD_E_PORT  &= ~(1<<LCD_ENABLE);
44
#define lcdSetRegSelect()   LCD_RS_PORT |=  (1<<LCD_REGSELECT)
45
#define lcdClearRegSelect() LCD_RS_PORT &= ~(1<<LCD_REGSELECT)
46
 
47
 
48
 
49
/************************************************************************/
50
/*  Definieren eines Sonderzeichen                                                                              */
51
/*      Parameter:                                                                                                                      */
52
/*  uint8_t  lcd_addr   : Adresse, 1.Adresse 0                                                  */
53
/*  char    *lcd_zeichen: Zeiger auf das 1. Byte der Zeichendefinition  */
54
/*                                                                                                                                              */
55
/************************************************************************/
56
void lcdWriteCGRAM(uint8_t lcd_addr, char *lcdChr)
57
{ int8_t i;
58
 
59
  lcdSendInstruction(INSTRUCTION_Table_0);
60
  for(i = 0; i < 8; i++)
61
  {
62
    lcdSendInstruction(SET_CGRAM | (lcd_addr * 8 + i)); // CG RAM Adresse
63
    lcdPutc(lcdChr[i]);  // Data Write 8x Pixelzeile
64
  }
65
  lcdSendInstruction(INSTRUCTION_Table_1);
66
}
67
 
68
/************************************************************************/
69
/*  Definieren von n <= 8 Sonderzeichen                                                                 */
70
/*      Parameter:                                                                                                                      */
71
/*  SpecialChr_t lcdChr   : Array mit Sonderzeichen                                             */
72
/*  uint8_t      quantity : Anzahl der zu übertragenen Sonderzeichen    */
73
/*                                                                                                                                              */
74
/************************************************************************/
75
void lcdWriteCGRAM_Array(SpecialChr_t lcdChr, uint8_t quantity)
76
{
77
  for (uint8_t i = 0; i < quantity; i++)
78
    lcdWriteCGRAM(i, lcdChr[i]); // Sonderzeichen in CGRAM der LCD schreiben
79
}
80
 
81
/************************************************************************************/
82
/*  sendet ein Nibble (4 Bit) zum LCD-Controller                                                                        */
83
/*      Parameter:                                                                                                                                              */
84
/*  char data   :Byte                                                                                                                           */
85
/*                                                                                                                                                                      */
86
/************************************************************************************/
87
void lcdSendNibble(char data)
88
{
89
  LCD_DATA_PORT |= (data & 0x0f);
90
  LCD_DATA_PORT &= (data | 0xf0);
91
  lcdSetEnable();
92
  _delay_us(2);
93
  lcdClearEnable();
94
  _delay_us(30);                // nach Datenblatt > 26,3µs
95
}
96
 
97
/************************************************************************************/
98
/*  sendet 8 Bit (2 Nibble) zum LCD-Controller                                                                          */
99
/*      Parameter:                                                                                                                                              */
100
/*  char data   :Byte                                                                                                                           */
101
/*                                                                                                                                                                      */
102
/************************************************************************************/
103
void lcdSendByte(char data)
104
{
105
  lcdSendNibble(data>>4);
106
  lcdSendNibble(data);
107
}
108
 
109
/************************************************************************************/
110
/*  sendet instruction zum LCD-Controller                                                                                       */
111
/*      Parameter:                                                                                                                                              */
112
/*  char instruction    :Byte                                                                                                           */
113
/*                                                                                                                                                                      */
114
/************************************************************************************/
115
void lcdSendInstruction(char instruction)
116
{
117
  lcdClearRegSelect();          // LCD-RS für Instruktionen
118
  lcdSendByte(instruction);
119
}
120
 
121
/************************************************************************************/
122
/*  sendet ein Zeichen zum LCD-Display                                                                                          */
123
/*      Parameter:                                                                                                                                              */
124
/*  char        c       :Zeichen                                                                                                                        */
125
/*                                                                                                                                                                      */
126
/************************************************************************************/
127
void lcdPutc(char c)
128
{
129
  lcdSetRegSelect();            // LCD-RS für Daten
130
  lcdSendByte(c);
131
}
132
 
133
/************************************************************************************/
134
/*  sendet einen String zum LCD-Display                                                                                         */
135
/*      Parameter:                                                                                                                                              */
136
/*  char        *str :Zeichenkette                                                                                                              */
137
/*                                                                                                                                                                      */
138
/************************************************************************************/
139
void lcdPuts(char *str)
140
{
141
  uint8_t l;
142
  uint8_t pos = 0;
143
 
144
  for(l = 0; str[l] != 0; l++)
145
    // funtioniert nur von Zeile 0 an, da aktuelle Zeile nicht bekannt! Kein read!
146
        // man könnte pos bei lcdSendByte, lcdGotoXY und lcdClear abhängig von Steuerung mitzählen
147
        if(str[l] == '\n')
148
    {
149
      if (pos >= LCD_LINES)
150
            pos = 0;
151
          else
152
            pos++;
153
      lcdGotoXY(0, pos);
154
    }
155
    else
156
      lcdPutc(str[l]);
157
}
158
 
159
/************************************************************************************/
160
/*  Löscht Inhalt auf LCD-Display                                                                                                       */
161
/*                                                                                                                                                                      */
162
/************************************************************************************/
163
void lcdClear()
164
{
165
  lcdSendInstruction(CLEAR_DISPLAY);
166
  _delay_ms(2);
167
}
168
 
169
/************************************************************************************/
170
/*  Setzt Kontrast auf LCD-Display                                                                                                      */
171
/*      Parameter:                                                                                                                                              */
172
/*  uint8_t contrast :Wert vo 0 bis max 63                                                                                      */
173
/*                                                                                                                                                                      */
174
/************************************************************************************/
175
void lcdContrast(uint8_t dogm, uint8_t contrast)
176
{ uint8_t power_contrast = POWER_CONTRAST;
177
 
178
  if(dogm == DOGM5V) {
179
    power_contrast &= ~(1<<BON);
180
  }
181
  lcdSendInstruction(INSTRUCTION_Table_1);
182
  lcdSendInstruction(CONTRAST_SET | (contrast & 0x0F));
183
  lcdSendInstruction(power_contrast | ((contrast>>4) & 0x03));
184
}
185
 
186
//***********************************************************************************/
187
/*  Setzt setzt den Cursor zur Position x/y                                                                                     */
188
/*      Parameter:                                                                                                                                              */
189
/*  uint8_t x, :Position Spalte                                                                                                         */
190
/*  uint8_t y, :Position Zeile                                                                                                          */
191
/*                                                                                                                                                                      */
192
/************************************************************************************/
193
void lcdGotoXY(uint8_t x, uint8_t y)
194
{ uint8_t pos;
195
 
196
  if(x > LCD_COLS)      x = 0;
197
  if(y > LCD_LINES)     y = 0;
198
  pos = y * LCD_COLS + x;
199
  lcdSendInstruction(SET_DDRAM_ADDR | pos);
200
}
201
 
202
/************************************************************************************/
203
/*  Initialisiert den LCD-Controller und der Atmega-Ausgänge                                            */
204
/*      Parameter:                                                                                                                                              */
205
/*  uint8_t dogm         :0=3,3V oder 1=5V DOGM                                                                                 */
206
/*  uint8_t contrast :Wert vo 0 bis max 63                                                                                      */
207
/*  uint8_t cursor       :Darstellung des Cursors ein oder 0 aus                                                */
208
/*  uint8_t blink        :Cursor blinken, 0 kein blinken                                                                */
209
/*                                                                                                                                                                      */
210
/************************************************************************************/
211
void lcdInit(uint8_t dogm, uint8_t contrast, uint8_t cursor, uint8_t blink)
212
{ uint8_t bias_set = BIAS_SET;
213
  uint8_t follower_ctrl  = FOLLOWER_CONTROL;
214
  uint8_t power_contrast = POWER_CONTRAST;
215
 
216
  LCD_BACKLIGHT_DDR |= (1<<LCD_BACKLIGHT);
217
  LCD_E_DDR |= (1<<LCD_ENABLE);
218
  LCD_RS_DDR |= (1<<LCD_REGSELECT);
219
  LCD_DATA_DDR |= (1<<LCD_DATA7) | (1<<LCD_DATA6) | (1<<LCD_DATA5) | (1<<LCD_DATA4);
220
 
221
  lcdClearEnable();
222
  _delay_ms(40);                        // lt. Datenblatt muss > 40ms nach Power On or ext. Reset
223
 
224
  if(dogm == DOGM5V) {
225
    follower_ctrl &= ~(1<<RAB1);
226
        bias_set |= (1 << BS);
227
    power_contrast &= ~(1<<BON);
228
  }
229
 
230
  //Initialisierung für DOGM (mit ST7036) 4 Bit Mode
231
  lcdClearRegSelect();          // LCD-RS für Instruktionen
232
  lcdSendNibble(FUNCTION_SET_INIT_0>>4);
233
   _delay_ms(2);                        // lt. Datenblatt muss > 1,6ms Pause nach ersten Nibble
234
  lcdSendNibble(FUNCTION_SET_INIT_0);
235
  lcdSendInstruction(FUNCTION_SET_INIT_1);
236
  lcdSendInstruction(FUNCTION_SET_INIT_2);
237
  lcdSendInstruction(bias_set);
238
  lcdSendInstruction(CONTRAST_SET | (contrast & 0x0F));
239
  lcdSendInstruction(power_contrast | ((contrast>>4) & 0x03));
240
  lcdSendInstruction(follower_ctrl);
241
  lcdSendInstruction(INSTRUCTION_Table_0);
242
  lcdSendInstruction(DISPLAY_ON | (cursor & 0x01) << 1 | (blink & 0x01));
243
  lcdClear();
244
  lcdSendInstruction(ENTRY_MODE);
245
}