1 | #ifndef LCDROUTINE_H_
|
2 | #define LCDROUTINE_H_
|
3 |
|
4 | /************************************************************
|
5 | * definations test
|
6 | ************************************************************/
|
7 | //LCD Port
|
8 |
|
9 | #define LCD_DIR P2DIR
|
10 | #define LCD_OUT P2OUT
|
11 |
|
12 |
|
13 | #define LCD_D0 BIT0 // Befehlsatz D7
|
14 | #define LCD_D1 BIT1 // Befehlsatz D4
|
15 | #define LCD_D2 BIT2 // Befehlsatz D5
|
16 | #define LCD_D3 BIT3 // Befehlsatz D6
|
17 | #define LCD_D4 BIT4 // Befehlsatz D7
|
18 | #define LCD_D5 BIT5 // Befehlsatz D4
|
19 | #define LCD_D6 BIT6 // Befehlsatz D5
|
20 | #define LCD_D7 BIT7 // Befehlsatz D6
|
21 |
|
22 |
|
23 | //Ausgabe Pins
|
24 | #define LCD_PIN_RS BIT0 // Befehlsatz D4
|
25 | #define LCD_PIN_E BIT1 // Befehlsatz D5
|
26 | #define LCD_PIN_D4 BIT2 // Befehlsatz D4
|
27 | #define LCD_PIN_D5 BIT3 // Befehlsatz D5
|
28 | #define LCD_PIN_D6 BIT4 // Befehlsatz D6
|
29 | #define LCD_PIN_D7 BIT5 // Befehlsatz D7
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | /************************************************************
|
36 | * declarations
|
37 | ************************************************************/
|
38 | void delay_ms(unsigned int uint_delay); // Verzögerung
|
39 | void LCD_Clock(unsigned int loops); // erzeugt ein Clock-Singal
|
40 | void lcd_command(unsigned char uch_command); //sendet command
|
41 | void LCD_Init(void); // Initialisierung
|
42 | void LCD_Clear(void); // löscht das Display und setzt Cursor den Anfang zurück
|
43 | void LCD_CursorHome(void); // Cursor auf Startpostion 0
|
44 | void LCD_OutChar(char ch_data); // gibt einen Character aus
|
45 | void LCD_OutString( const char* c ); // gibt einen String aus
|
46 |
|
47 | unsigned short ush_test_array = 0;
|
48 | unsigned short i = 0;
|
49 |
|
50 | /************************************************************
|
51 | * functions
|
52 | ************************************************************/
|
53 |
|
54 | void delay_ms(unsigned int uint_delay)
|
55 | {
|
56 | while (uint_delay--) // Loop für Delay
|
57 | {
|
58 | __delay_cycles(1000); // Delay Masterclock
|
59 | }
|
60 | }
|
61 |
|
62 | void LCD_Clock(unsigned int loops) // erzeugt ein Clock-Singal
|
63 | {
|
64 | while(loops--)
|
65 | {
|
66 | LCD_OUT &= ~LCD_PIN_E; // zuerst das clock-bit sicherheitshalber auf low
|
67 | delay_ms(20); // 20ms Delay
|
68 | LCD_OUT |= LCD_PIN_E; // clock-bit auf high
|
69 | delay_ms(20); // 20ms Delay
|
70 | LCD_OUT &= ~LCD_PIN_E; // und jetzt wieder auf low
|
71 | delay_ms(20); // 20ms Delay
|
72 | }
|
73 | }
|
74 |
|
75 | void LCD_Init(void) // Initialisierung
|
76 | {
|
77 | LCD_OUT &= ~LCD_mask; // Enable, RW und RS auf 0 und D4 - D7 = 0
|
78 | delay_ms(250); // 250ms Delay
|
79 |
|
80 | LCD_OUT |= LCD_PIN_D5 + LCD_PIN_D4; // Befehlssatz: Funktioen
|
81 | LCD_Clock(1); // befehl ausfuehren
|
82 | delay_ms(250); // warten
|
83 |
|
84 | LCD_Clock(1); // befehl ausfuehren
|
85 | delay_ms(200); // warten
|
86 |
|
87 | LCD_Clock(1); // befehl ausfuehren
|
88 | delay_ms(30); // warten
|
89 |
|
90 | LCD_OUT |= LCD_D5
|
91 | // + LCD_D4; // 0 = 4-Bit Interface; 1 = 8-Bit Interface
|
92 | ;
|
93 | LCD_Clock(1); // befehl ausfuehren
|
94 | delay_ms(30); // warten
|
95 | //LCD_Clear();
|
96 |
|
97 | //lcd_command(LCD_D2 + LCD_D1); // Befehlssatz: Modus festlegen --> Cursor inkrementieren(rechts)
|
98 | //lcd_command(LCD_D3 + LCD_D2 + LCD_D1 ); // Befehlssatz: Display/Cursor --> Display an; Cursor an
|
99 | //lcd_command(LCD_D4 + LCD_D2 ); // Befehlssatz: Cursor/Display schieben --> Cursor rechts schieben
|
100 | //lcd_command(LCD_D5 + LCD_D3 ); // Befehlssatz: Funktionen --> 2/4 Zeilen,
|
101 |
|
102 | }
|
103 |
|
104 | void LCD_Clear(void) // löscht das Display und setzt Cursor den Anfang zurück
|
105 | {
|
106 | lcd_command(LCD_D0); // clear display
|
107 | delay_ms(30); // 30ms Delay
|
108 | LCD_CursorHome(); // setzt coursor auf home
|
109 | }
|
110 |
|
111 | void LCD_CursorHome(void) // Setzt Cursor den Anfang zurück
|
112 | {
|
113 | lcd_command(LCD_D1); // Cursor Homeposition
|
114 | delay_ms(30); // 30ms Delay
|
115 | }
|
116 |
|
117 | void LCD_OutChar(char ch_data)
|
118 | {
|
119 | unsigned char uch_temp = ch_data; // übergibt das byte
|
120 | LCD_OUT &= ~LCD_mask; // Enable, RW und RS auf 0 und D4 - D7 = 0
|
121 | LCD_OUT |= LCD_PIN_RS; // Wählt Datenregister aus
|
122 |
|
123 | //High Nibble
|
124 | LCD_OUT = (ch_data & 0xF0); // 4 Bits inkrementieren und maskieren und anschließen high nibble ausgeben
|
125 | LCD_Clock(1); // Clock signal
|
126 | //Low Nibble
|
127 | LCD_OUT = ((uch_temp << 4) & 0xF0); // unteres nibble maskieren und ausgeben
|
128 | LCD_Clock(1); // Clock singal
|
129 | }
|
130 |
|
131 | void lcd_command(unsigned char uch_command)
|
132 | {
|
133 | unsigned char uch_temp = uch_command; // übergibt das byte
|
134 | LCD_OUT &= ~LCD_mask; // Enable, RW und RS auf 0 und D4 - D7 = 0
|
135 | LCD_OUT &= ~LCD_PIN_RS; // wählt Steuerbefehl aus
|
136 |
|
137 | //High Nibble
|
138 | P1OUT = (uch_command & 0xF0); // 4 Bits inkrementieren und maskieren und anschließen high nibble ausgeben
|
139 | LCD_Clock(1); // Clock signal
|
140 | //Low Nibble
|
141 | P1OUT = ((uch_temp << 4) & 0xF0); // unteres nibble maskieren und ausgeben
|
142 | LCD_Clock(1); // Clock singal
|
143 | }
|
144 |
|
145 | void LCD_OutString( const char *c ) // gibt einen String aus
|
146 | {
|
147 | while( *c != '\0' )
|
148 | {
|
149 | LCD_OutChar( *c++ );
|
150 | }
|
151 | }
|
152 |
|
153 |
|
154 |
|
155 | #endif /*LCDROUTINE_H_*/
|