Forum: Mikrocontroller und Digitale Elektronik Problem mit LCD an Atmega8 4Bit IO-Mode


von Hurschtl (Gast)


Angehängte Dateien:

Lesenswert?

Hallo zusammen,

ich habe gerade ein verzwicktes Problem bzw ist es wahrscheinlich ein 
Dämlichkeitsfehler. Ich möchte ein Crystalfontz LCD (HD44780 kompatibel) 
an einem Atmega8 betreiben.
Schliess eich alles vermeindlich richtig an, sehe ich nichts. Verdrehe 
ich die Datenleitungen, sehe ich einen blinkenden Cursor inkl. 
Kauderwelsch.
Ich verwende die aktuellste Version von Peter Fleurys LCD Lib.

Daten LCD:

 Pin No.  Symbol   Level   Description
 1   VSS   0V     Ground
 2   VDD   5.0V     Supply Voltage for logic
 3  VO   (Variable)   Operating voltage for LCD
 4   RS   H/L     H: DATA, L: Instruction code
 5   R/W   H/L     H: Read(MPU?Module) L: Write(MPU?Module)
 6   E   H,H?L     Chip enable signal
 7   DB0   H/L     Data bit 0
 8   DB1   H/L     Data bit 1
 9   DB2   H/L     Data bit 2
 10   DB3   H/L     Data bit 3
 11   DB4   H/L     Data bit 4
 12   DB5   H/L     Data bit 5
 13   DB6   H/L     Data bit 6
 14   DB7   H/L     Data bit 7
 15   A   -     LED +
 16   K   -     LED -

Anpassung an lcd.h in Verbindung mit dem Datenblatt: 
https://www.crystalfontz.com/products/document/200/CFAH2004AYYHJPE.pdf

#ifndef LCD_LINES
#define LCD_LINES           4     /**< number of visible lines of the 
display */
#endif
#ifndef LCD_DISP_LENGTH
#define LCD_DISP_LENGTH    20     /**< visibles characters per line of 
the display */
#endif
#ifndef LCD_LINE_LENGTH
#define LCD_LINE_LENGTH  0x40     /**< internal line length of the 
display    */
#endif
#ifndef LCD_START_LINE1
#define LCD_START_LINE1  0x00     /**< DDRAM address of first char of 
line 1 */
#endif
#ifndef LCD_START_LINE2
#define LCD_START_LINE2  0x40     /**< DDRAM address of first char of 
line 2 */
#endif
#ifndef LCD_START_LINE3
#define LCD_START_LINE3  0x14     /**< DDRAM address of first char of 
line 3 */
#endif
#ifndef LCD_START_LINE4
#define LCD_START_LINE4  0x54     /**< DDRAM address of first char of 
line 4 */
#endif
#ifndef LCD_WRAP_LINES
#define LCD_WRAP_LINES      1     /**< 0: no wrap, 1: wrap at end of 
visibile line */
#endif


#define LCD_IO_MODE      1            /**< 0: memory mapped mode, 1: IO 
port mode */
#if LCD_IO_MODE
#ifndef LCD_PORT
#define LCD_PORT         PORTC        /**< port for the LCD lines   */
#endif
#ifndef LCD_DATA0_PORT
#define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
#endif
#ifndef LCD_DATA1_PORT
#define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
#endif
#ifndef LCD_DATA2_PORT
#define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
#endif
#ifndef LCD_DATA3_PORT
#define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
#endif
#ifndef LCD_DATA0_PIN
#define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
#endif
#ifndef LCD_DATA1_PIN
#define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
#endif
#ifndef LCD_DATA2_PIN
#define LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */
#endif
#ifndef LCD_DATA3_PIN
#define LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */
#endif
#ifndef LCD_RS_PORT
#define LCD_RS_PORT      PORTB     /**< port for RS line         */
#endif
#ifndef LCD_RS_PIN
#define LCD_RS_PIN       1            /**< pin  for RS line         */
#endif
#ifndef LCD_RW_PORT
#define LCD_RW_PORT      LCD_PORT     /**< port for RW line         */
#endif
#ifndef LCD_RW_PIN
#define LCD_RW_PIN       5            /**< pin  for RW line         */
#endif
#ifndef LCD_E_PORT
#define LCD_E_PORT       LCD_PORT     /**< port for Enable line     */
#endif
#ifndef LCD_E_PIN
#define LCD_E_PIN        4            /**< pin  for Enable line     */
#endif


Meine main.c:

#include <avr/io.h>
#include <util/delay.h>
#include "lcd.c"

int main(void)
{
    lcd_init(LCD_DISP_ON_CURSOR_BLINK);  /* initialize display, cursor 
off */
    while (1)          /* loop forever */
    {
        lcd_clrscr();                   /* clear the screen*/
        lcd_puts("ho");                 /* displays the string on lcd*/
        _delay_ms(50);
    }
    return 0;
}

Anbei mein Testaufbau. Ich verwende PORTC + PB1 um das LCD anzusteuern.
Seht ihr irgendwas abgrundtief Falsches? Aktuell stochere ich nur in 
Trüben.
Den Trimmer habe ich für VO auf 1K eingestellt.
Wie gesagt, verdrehe ich Data0 - 3 sehe ich was, verstehe es aber nicht, 
warum...
Also normalerweise sollte es so sein:
PC0 -> LCD_DATA0_PIN (Data Bit 4)
PC1 -> LCD_DATA1_PIN (Data Bit 5)
PC2 -> LCD_DATA2_PIN (Data Bit 6)
PC3 -> LCD_DATA3_PIN (Data Bit 7)

Danke für eure Zeit,
Hurschtl

von Karoly (Gast)


Lesenswert?

versuche so:

int main(void)
{
    lcd_init(LCD_DISP_ON_CURSOR_BLINK);  /* initialize display, cursor
off */

     lcd_clrscr();                   /* clear the screen*/
     lcd_puts("ho");                 /* displays the string on lcd*/


    while (1)          /* loop forever */
    {

        _delay_ms(50);
    }

}

von Karl M. (Gast)


Lesenswert?

Hurschtl ,

man sollte auch ALLE Leitungen Vcc, Avcc und Gnd, AGnd anschließen und 
mit einem 100nF Kondensatore versehen - Pflicht !

Das steht auch alles im Datenblatt und den Atmel Application Notes.

Lesen bildet.

von Hurschtl (Gast)


Lesenswert?

Danke für den Hinweis, den Text aus der Schleife rauszunehmen, macht so 
natürlich keine Sinn. Deine Version ändert jedoch nichts.

von Karl M. (Gast)


Lesenswert?

Nachtrag,

bitte auch hier mal nachsehen:

Beitrag "LCD Display es werden keine Buchstaben angezeigt."

von Hurschtl (Gast)


Lesenswert?

Karl:
Ok, da war er, der Dämlichkeitsfehler... :-(
"It should be externally connected to VCC, even if the ADC is not used"
Danke für die schnelle Hilfe!

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
Noch kein Account? Hier anmelden.