LCD_Display_3.c


1
//#############################################################################
2
//
3
// Programmierung LCD Display
4
//
5
//Autor: Johannes Losch  
6
//Datum:11.05.2011
7
//Version:0.1
8
//
9
//Beschreibung der Funktion: Ansteuerung eines LCD-Displays 
10
//
11
//Parameter:   typ
12
//
13
//Rückgabe:    XXXXXXXXX0-ok 
14
//Rückgabe:    XXXXXXXXX1-nicht ok
15
//Rückgabe:    XXXXXXXX1X-Fehler1
16
//Rückgabe:    XXXXXXX1XX-Fehler2
17
//Rückgabe:    XXXXXX1XXX-Fehler3
18
//
19
//
20
//############################################################################
21
22
23
#include <math.h>
24
#include <avr/io.h>   
25
#include <Seriell.h>
26
#include <util/delay.h> 
27
#include <dac_adc.h>
28
#include <lcd_routines2.h>
29
#include <avr/pgmspace.h>
30
31
#define Kontrast 100 // Kontrasteinstellung
32
#define PSTR   (s) ((const PROGMEM char*)(s))
33
34
35
36
int main (void) {            
37
 
38
  clock_init();
39
40
  
41
     
42
  init_RS232 (F0, 115200); //921600 115200
43
44
45
  
46
  _delay_ms(100);
47
 
48
   // Initialisierung des LCD
49
  
50
 
51
// Snippet 1
52
// Initialise the LCD Display
53
lcd_init();
54
 
55
 
56
// Snippet 2
57
// clear display
58
lcd_clear_and_home();
59
60
 
61
 // Snippet 3
62
// display "Hello World" on LCD first line
63
lcd_line_one();
64
lcd_write_string_p(PSTR("Hello World\0"));    // message from flash space
65
66
67
  
68
   while(1) {                
69
      
70
  
71
      
72
    
73
//////////// DAC Kontrasteinstellung ////////////////////
74
  
75
  DACB.CH0DATA = Kontrast;
76
  
77
  // warte bis sendung fertig
78
       while (!DACB.STATUS & DAC_CH0DRE_bm) ;
79
80
/////////////////////////////////////////////////////////
81
82
83
              
84
          
85
86
87
88
 
89
   }                      
90
 
91
      return 0;                 
92
}
93
94
95
96
97
void clock_init(void)
98
{
99
  //Oszillator auf 32Mhz stellen
100
  OSC.CTRL |= OSC_RC32MEN_bm;
101
  // Warten bis der Oszillator bereit ist
102
  while(!(OSC.STATUS & OSC_RC32MRDY_bm));
103
  CCP = CCP_IOREG_gc;
104
  CLK.CTRL = (CLK.CTRL & ~CLK_SCLKSEL_gm) | CLK_SCLKSEL_RC32M_gc;
105
}