Ich versuche grade ein Display zu bewegen, etwas anzuzeigen um die
Hintergründe zu verstehen.
Dabei habe ich mir das Datenblatt genommen und versucht den Quelltext
dafür zu schreiben.
Leider funktioniert das nicht so, wie es soll und die Fehler kann ich
mir nicht erklären.
Die Hardware und Verkabelung scheinen korrekt zu sein, da andere
Quelltexte die man so im Netz findet funktionieren.
Es handelt sich um ein 16x2 Display (HD44780).
1.) Es werden nach dem Hochladen auf dem MC nur Oben weiße Kästen
angezeigt.
2.) Wenn ich Debugge und jeden Zeile einzeln durchgehe, funktioniert es
teilweise.
Unterbreche ich die Spannung, sollte ja eigentlich der Text angezeigt
werden, aber das Display bleibt leer. (Ohne Balken Oben).
Die Zeiten, die im Datenblatt angegeben sind für die Initialisierung
usw. habe ich schon erhöht, leider blieb das auch ohne Erfolg.
Ich würde mich freuen, wenn sich mal jemand den Quelltext ansehen würde
und mir evtl. auf die Sprünge hilft, damit ich den Fehler verstehen.
*LCD.h*
1 | #ifndef LCD_H_
|
2 | #define LCD_H_
|
3 |
|
4 | #ifndef F_CPU
|
5 | #undef F_CPU
|
6 | #define F_CPU 16000000UL
|
7 | #endif
|
8 |
|
9 | #include <avr/io.h>
|
10 | #include <util/delay.h>
|
11 |
|
12 | #define BACKLIGHTDIR DDRB
|
13 | #define BACKLIGTPORT PORTB
|
14 | #define BL PORTB0 // PB0 - Back light VCC Pin
|
15 |
|
16 | #define LCDPORT PORTD
|
17 | #define LCDDIR DDRD
|
18 |
|
19 | #define RS PORTD0 // PD0
|
20 | #define EN PORTD1 // PD1
|
21 | #define D4 PORTD4 // PD4
|
22 | #define D5 PORTD5 // PD5
|
23 | #define D6 PORTD6 // PD6
|
24 | #define D7 PORTD7 // PD7
|
25 |
|
26 | #define CMD_CLR 0x01 // Clear Display
|
27 | #define CMD_HOME 0x02 // Display Home
|
28 | #define CMD_FUNC_SET 0x28 // 4-Bit Mode, 2-Line Display, 5x8 character Font
|
29 | #define CMD_ENTRYMODE 0x06 // Increment cursor, no Shift
|
30 | #define CMD_LCD_OFF 0x08 // Display off, Cursor off, Blinking off
|
31 | #define CMD_LCD_ON 0x0C // Display on, Cursor off, Blinking off
|
32 | #define CMD_CURS_ON 0x0E // Display on, Cursor on, Blinking off
|
33 | #define CMD_Blink_ON 0x0F // Display on, Cursor on, Blinking on
|
34 |
|
35 | void Backlight(unsigned int onoff);
|
36 | void InitLCD(void);
|
37 | void SendCMD(char cmd);
|
38 | void LCD_Print (char *data);
|
39 | void Send(char s);
|
40 | void LCD_Clear(void);
|
41 |
|
42 |
|
43 | #endif /* LCD_H_ */
|
*LCD.c*
1 | #include "LCD.h"
|
2 |
|
3 |
|
4 | void Backlight(unsigned int onoff)
|
5 | {
|
6 | if (onoff == 1)
|
7 | BACKLIGTPORT |= (1 << BL);
|
8 | else
|
9 | BACKLIGTPORT &= ~ (1 << BL);
|
10 | }
|
11 |
|
12 | void InitLCD(void)
|
13 | {
|
14 | BACKLIGHTDIR = 0b00000001;
|
15 | LCDDIR = 0b11111111;
|
16 | _delay_ms(20);
|
17 | SendCMD(CMD_FUNC_SET);
|
18 | SendCMD(CMD_ENTRYMODE);
|
19 | SendCMD(CMD_LCD_ON);
|
20 | SendCMD(CMD_CLR);
|
21 | SendCMD(CMD_HOME);
|
22 | }
|
23 |
|
24 | void SendCMD(char cmd)
|
25 | {
|
26 | LCDPORT &= ~(1 << RS);
|
27 | Send(cmd);
|
28 | _delay_ms(2);
|
29 | }
|
30 |
|
31 | void LCD_Print(char *data)
|
32 | {
|
33 | for (int i=0; data[i]!=0; i++)
|
34 | {
|
35 | LCDPORT |= (1 << RS);
|
36 | Send(data[i]);
|
37 | }
|
38 | }
|
39 |
|
40 | void Send(char s)
|
41 | {
|
42 | LCDPORT = (LCDPORT & 0x0F) | (s & 0xF0);
|
43 | LCDPORT |= (1 << EN);
|
44 | _delay_us(1);
|
45 | LCDPORT &= ~(1 << EN);
|
46 | _delay_us(200);
|
47 |
|
48 | LCDPORT = (LCDPORT & 0x0F) | (s << 4);
|
49 | LCDPORT |= (1 << EN);
|
50 | _delay_us(1);
|
51 | LCDPORT &= ~(1 << EN);
|
52 | _delay_us(200);
|
53 | }
|
54 |
|
55 | void LCD_Clear(void)
|
56 | {
|
57 | SendCMD(CMD_CLR);
|
58 | SendCMD(CMD_HOME);
|
59 | }
|