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
es gibt hier dutzende IchKannMeinLCDNichtAnsteuernBinIchZuBlödOderWasBitteSchreibtMeinenCodeLö stMeinProblem-Beitrag Suckfunktion: http://www.mikrocontroller.net/search Mahlzeit <°)))o><
@ 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
PA6 ist vermutlich auch schon falsch. Ich tippe auf PA5. While Schleife sieht auch nicht glücklich aus! Es fehlen einfach die Grundlagen. AVR-GCC-Tutorial mal gründlich durchlesen, vor allem das Kapitel LCD-Ansteuerung hilft hier besonders weiter. Cheers
wärs nicht besser so: PORTA |= (1 << PA6); //Enable-Pin High PORTA = 0b01000011; //8-Bit PORTA &= ~(1<<PA6); //Enable-Pin Low
Bitte nochmal in die Grundlagen gucken, dann den Sinn von Enable verstehen und dann das eben geschriebene nochmal überdenken. Es wär nicht besser so, weil so nicht geht -> siehe der Sinn des Enable-Signals.
Hallo, Bei wieviel MHz tut sich denn nix ? Bei mir (16MHz) stehen da nicht jede Menge NOPs im Code, ohne die das LCD nur Schrott anzeigt. Edit: Lothar, Du hast ja sooo recht, jetzt seh ichs auch. Gruss, Michael
@ 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 ...
Hallo, na überleg mal: PORTA |= (1 << PA6); //Enable-Pin High PORTA = 0b00000011; //8-Bit -----> Enable wieder LOW, oder PORTA &= ~(1<<PA6); //Enable-Pin Low Gruss, Michael
@ 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);
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?
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.
