LCD_Initialisierung

Gast #983880
Lesenswert?

Habe folgendes Problem:

Initialisierung des Display (Controller HD44780) funktioniert nicht.

Folgender Code sollte einen blinkenden Cursor ausgeben:

#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/lcdvorlage.h>
#include <util/delay.h>


#define F_CPU 16000000
int main(void)
{
DDRA = 0xFF;
//Step 1 -Time until the modul has initialized itself internally
_delay_ms(50);
//Step 2 -set 8 bit mode
PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00000011;  //8-Bit
PORTA &= ~(1<<PA6);  //Enable-Pin Low

_delay_ms(5);
PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00000011;  //8-Bit
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_us(160);

PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00000011;  //8-Bit
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_us(160);
//Step3 -set 4 bit mode
PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00000010;  //4-Bit Modus - MSB
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);
PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00000010;  //4-Bit Modus - LSB
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);
//Step4 -select the connected display
PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00101000;  //4-Bit Modus . LSB
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);
//Step5 -Activate the display, turn on the cursor, turn on blinking
PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00001111;  //Display AN, Cursor AN - MSB
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);
PORTA |= (1 << PA6); //Enable-Pin High
PORTA = 0b00001111;  //Display AN, Cursor AN - LSB
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);



while(1);
}

Vielleicht kann mir jemand sagen wo das Problem liegt?! Danke
Moderator (Firma: Titel) Persönliche Seite #984135
Lesenswert?

@  Manfred B. (vorbeigeschlendert)
> Mahlzeit
Jetzt schon? ;-)


> PORTA |= (1 << PA6); //Enable-Pin High
> PORTA = 0b00000010;  //4-Bit Modus - MSB
> PORTA &= ~(1<<PA6);  //Enable-Pin Low
Zeichne mal die Bitmuster vom Port A auf (Logikanalyzer, Oszi oder Blatt 
Papier). Dann siehst du, dass der Enable schon in der 2. Zeile wieder 
zurückgesetzt wird. Deine Kommandos kommen nie beim LCD an.

Das könnte schon helfen:
 PORTA = 0b00000010;  //4-Bit Modus - MSB
 PORTA |= (1 << PA6); //Enable-Pin High
 PORTA &= ~(1<<PA6);  //Enable-Pin Low
Moderator (Firma: Titel) Persönliche Seite #984276
Lesenswert?

@  Michael Appelt (micha54)
> Du hast ja sooo recht...
Ja, ich weiß, aber womit? ;-)

@  Hannes (Gast)
> aber es tut sich auch so nichts
Ein wenig noch aufs Datenblatt schauen, das Timing des Enable-Signals 
sollte natürlich schon eingehalten werden (Bild). Michael hat das auch 
bemerkt:
> ... jede Menge NOPs im Code ...
Angehängte Dateien:
Moderator (Firma: Titel) Persönliche Seite #984766
Lesenswert?

@ Michael Appelt
> na überleg mal:
>
> PORTA |= (1 << PA6); //Enable-Pin High
> PORTA = 0b00000011;  //8-Bit -----> Enable wieder LOW, oder
> PORTA &= ~(1<<PA6);  //Enable-Pin Low
Meinst du mich?
Das hatte ich doch in meinem ersten Post schon geschrieben...


@ Hannes
>wärs nicht besser so:
>PORTA |= (1 << PA6); //Enable-Pin High
>PORTA = 0b01000011;  //8-Bit
>PORTA &= ~(1<<PA6);  //Enable-Pin Low
Nirgendwo im DB wird geschrieben, dass sich die Daten während 
Enable=High ändern müssen. Es ist nur verlangt, dass sie eine bestimmte 
Zeit vor der fallenden Flanke von Enable stabil sind (Data-Setup min 
80ns und Data-Hold min 10ns). Es spricht also nichts dagegen, die Daten 
schon vorher anzulegen.

Dann probiers mal so:
 PORTA = 0b00000010;  //4-Bit Modus - MSB
 PORTA |= (1 << PA6); //Enable-Pin High
 _delay_ms(1);
 PORTA &= ~(1<<PA6);  //Enable-Pin Low
 _delay_ms(5);
Gast #984892
Lesenswert?

Habs jetzt folgendermaßen probiert:

#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/lcdvorlage.h>
#include <util/delay.h>


#define F_CPU 16000000
int main(void)
{
DDRA = 0xFF;
//Step 1 -Time until the modul has initialized itself internally
_delay_ms(50);
//Step 2 -set 8 bit mode

PORTA = 0b00000011;  //8-Bit
PORTA |= (1 << PA6); //Enable-Pin High
_delay_ms(1);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);

PORTA = 0b00000011;  //8-Bit
PORTA |= (1 << PA6); //Enable-Pin High
_delay_us(160);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_us(100);

PORTA = 0b00000011;  //8-Bit
PORTA |= (1 << PA6); //Enable-Pin High
_delay_us(160);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_us(100);

//Step3 -set 4 bit mode
PORTA = 0b00000010;  //4-Bit Modus - MSB
PORTA |= (1 << PA6); //Enable-Pin High
_delay_ms(1);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);

/*PORTA = 0b00000010;  //4-Bit Modus - LSB
PORTA |= (1 << PA6); //Enable-Pin High
_delay_ms(1);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);*/

//Step4 -select the connected display
PORTA = 0b00101000;  //4-Bit Modus - LSB
PORTA |= (1 << PA6); //Enable-Pin High
_delay_ms(1);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);

//Step5 -Activate the display, turn on the cursor, turn on blinking
PORTA = 0b00001111;  //Display AN, Cursor AN - MSB
PORTA |= (1 << PA6); //Enable-Pin High
_delay_ms(1);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);

/*PORTA = 0b00001111;  //Display AN, Cursor AN - LSB
PORTA |= (1 << PA6); //Enable-Pin High
_delay_ms(1);
PORTA &= ~(1<<PA6);  //Enable-Pin Low
_delay_ms(5);*/

while(1);
}

tut sich aber noch immer nichts, liegts vielleicht daran dass ich im 4 
bit modes arbeite, da muss ich mir ja zuerst das höherwertige Nibble 
holen und dann das niederwertige, kann dass sein, wie sieht dass dann 
aus?

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