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
#define F_CPU 8000000UL    // oder deine Taktrate
22
23
24
#include <math.h>
25
#include <avr/io.h>   
26
#include <Seriell.h>
27
#include <util/delay.h> 
28
#include <dac_adc.h>
29
#include <lcd_routines2.h>
30
#include <avr/pgmspace.h>
31
32
#define Kontrast 100 // Kontrasteinstellung
33
34
int lcd_putchar(char c, FILE *stream);      // Stream einbinden
35
36
static FILE mystdout = FDEV_SETUP_STREAM(dogm_putchar, NULL,
37
_FDEV_SETUP_WRITE);  // bindet printf() ein
38
39
40
41
42
43
int main (void) {            
44
 
45
46
47
     stdout = &mystdout; // bindet printf() ein
48
    
49
    clock_init();
50
    init_RS232 (F0, 115200); //921600 115200
51
  
52
  _delay_ms(100);
53
 
54
   // Initialisierung des LCD
55
  
56
 
57
// Snippet 1
58
// Initialise the LCD Display
59
lcd_init();
60
 
61
 
62
// Snippet 2
63
// clear display
64
lcd_clear_and_home();
65
66
67
68
69
//////////////////  PRINTF  //////////////////////////////////
70
71
lcd_line_one();
72
printf(" alles ok ");
73
74
//////////////////////////////////////////////////////////////
75
 // Snippet 3
76
// display "Hello World" on LCD first line
77
//lcd_line_one();
78
//lcd_write_string_p(PSTR("Hello World\0"));    // message from flash space
79
80
81
  
82
   while(1) {                
83
      
84
  
85
      
86
    
87
//////////// DAC Kontrasteinstellung ////////////////////
88
  
89
  DACB.CH0DATA = Kontrast;
90
  
91
  // warte bis sendung fertig
92
       while (!DACB.STATUS & DAC_CH0DRE_bm) ;
93
94
/////////////////////////////////////////////////////////
95
96
97
98
 
99
   }                      
100
 
101
      return 0;                 
102
}
103
104
105
106
107
void clock_init(void)
108
{
109
  //Oszillator auf 32Mhz stellen
110
  OSC.CTRL |= OSC_RC32MEN_bm;
111
  // Warten bis der Oszillator bereit ist
112
  while(!(OSC.STATUS & OSC_RC32MRDY_bm));
113
  CCP = CCP_IOREG_gc;
114
  CLK.CTRL = (CLK.CTRL & ~CLK_SCLKSEL_gm) | CLK_SCLKSEL_RC32M_gc;
115
}