Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

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