LCD Initialisierung ATMEGA8

Gast #1749217
Lesenswert?

Hallo,
Kann mir wer sagen, was an meine Initialisierung eines Displays am 
ATMEGA8 fehlt?
1
 /* 
2

3
PD2:  RS   = Enable
4
PD3:  E   = Enable
5
PD4:  DB4 = Datenbit 4
6
PD5:  DB5 = Datenbit 5
7
PD6:  DB6 = Datenbit 6
8
PD7:  DB7 = Datenbit 7
9

10
PB0:   Jumper R/W
11
PB1:  Jumper PWM
12

13
*/
14

15

16
#include <avr/io.h>
17

18
#ifndef F_CPU
19
#define F_CPU 3686400UL     
20
#endif
21

22
#include <util/delay.h>
23

24

25

26

27

28
int main (void)
29
{
30
void lcd_init( void )
31
{
32
    DDRD   = (1 << PIND2) | (1 << PIND3) | (1 << PIND4) | (1 << PIND5) | (1 << PIND6) | (1 << PIND7);    //Configured for the 4 Bit mode across port D
33
    PORTD   = (0 << PIND2) | (0 << PIND3) | (0 << PIND4) | (0 << PIND5) | (0 << PIND6) | (0 << PIND7);    //LCD - PORTD initialisieren
34
 
35
  
36
    _delay_ms(50);                              //Wait as many as 50 ms according to Power-ON
37
    
38
    
39
  PORTD   = (1 << PIND4) | (1 << PIND5) | (0 << PIND2);          //The display will be shifted into the initialisation mode according to send
40
                                      //0b0011xxxx (soft-reset) three times thereby RS = 0.
41
  PORTD   = (1 << PIND3);
42
  _delay_ms(5);
43
  
44

45
  PORTD   = (1 << PIND4) | (1 << PIND5) | (0 << PIND2);
46
  PORTD   = (1 << PIND3);
47
  _delay_us(100);
48

49
  PORTD   = (1 << PIND4) | (1 << PIND5) | (0 << PIND2);
50
    PORTD   = (1 << PIND3);
51

52
  PORTD   = (1 << PIND5);                          //LCD init 4 Bit
53
  PORTD   = (1 << PIND3);
54
  _delay_ms(5);
55

56
  PORTD   = (1 << PIND3) | (1 << PIND5);                  //LCD 2x16 konfig
57

58

59
                                      //LCD_cmd
60

61
  PORTD   = (1 << PIND3);                          //LCD_off
62
  PORTD   = (1 << PIND0);                          //LCD_clear
63
  PORTD   = (1 << PIND1) | (1 << PIND2);                  //set Entry-Mode
64

65
                                      //LCD_cmd
66
  PORTD   = (1 << PIND1) | (1 << PIND2) | (1 << PIND3);          //LCD_on    
67
  
68

69
  }
70
  
71
   lcd_init ();
72
  
73
  while (1)
74
  {
75

76
  };
77

78
  return (1);
79
}
Gast #1749237
Lesenswert?

Ok. Jetzt musst Du nur noch(tm) die Bitmanipulationen richtig(tm) 
hinbiegen.. folgendes funktioniert so nicht (bzw. nicht so wies soll.. 
habs kurz annotiert):
1
// im 4-bit-modus initialisieren, dazu.. data setzen.. unlesbar aber
2
// sollte klappen
3
PORTD   = (1 << PIND4) | (1 << PIND5) | (0 << PIND2);
4

5
// jetzt E(nable) setzen..
6
PORTD   = (1 << PIND3);
7
       ^ 
8
       ..und dabei data wieder löschen.. *hust*

An (fast) allen anderen Stellen analog.. Falls es noch nicht klar ist, 
dann lies mal unter [1] ein bisschen nach, insbesondere [2]. Und wenn Du 
schon dabei bist, dann empfehle ich Dir zur Verbesserung der Lesbarkeit 
dringend ein paar mehr ∗aussagekräftige∗ defines für die Pinnamen 
anzulegen, so wies in [3] vorgeschlagen wird :-)

HTH und HF

[1] http://www.mikrocontroller.net/articles/Bitmanipulation
[2] 
http://www.mikrocontroller.net/articles/Bitmanipulation#Bits_l.C3.B6schen
[3] http://www.mikrocontroller.net/articles/Bitmanipulation#Bits_setzen

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren