- Labornetzteil AliExpress         
Seite 1 von 2 12 LetzteLetzte
Ergebnis 1 bis 10 von 15

Thema: LCD Display mit KS0066U/KS0070B

  1. #1
    Neuer Benutzer Öfters hier
    Registriert seit
    22.03.2013
    Beiträge
    6

    LCD Display mit KS0066U/KS0070B

    Anzeige

    Praxistest und DIY Projekte
    Ich hoffe mir kann hier jemand bei meinem Problem helfen.

    Problemschilderung:
    Ich habe mir bei Reichelt ein LCD Display(Grün) bestellt
    http://www.reichelt.de/Hintergrund-g...r=LCD+162C+LED
    Ich habe mir die LCD Library von Peter Fleury runtergeladen.
    http://jump.to/fleury
    Den Mikrocontroller Atmega8 habe ich ohne Quarz laufen und nach der Pinbelegung von der lcd library auf einem Steckboard mit dem Display verbunden.
    Die Headerdatei lcd.h habe ich an meinem Controller nach Anleitung angepasst siehe Quellcode.
    um festzustellen ob das Display funktioniert habe ich ein kleines Testprogramm geschrieben und stellte fest das es nicht funktioniert.
    Hier erstmal die Codes:

    lcd.h von Peter Fleury:
    Code:
    #ifndef LCD_H_
    #define LCD_H_
    
    #ifndef LCD_H
    #define LCD_H
    /*************************************************************************
     Title	:   C include file for the HD44780U LCD library (lcd.c)
     Author:    Peter Fleury <pfleury@gmx.ch>  http://jump.to/fleury
     File:	    $Id: lcd.h,v 1.13.2.2 2006/01/30 19:51:33 peter Exp $
     Software:  AVR-GCC 3.3
     Hardware:  any AVR device, memory mapped mode only for AT90S4414/8515/Mega
    ***************************************************************************/
    
           
     @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury
     
     @see The chapter <a href="http://homepage.sunrise.ch/mysunrise/peterfleury/avr-lcd44780.html" target="_blank">Interfacing a HD44780 Based LCD to an AVR</a>
          on my home page.
    
    */
    
    /*@{*/
    
    #if (__GNUC__ * 100 + __GNUC_MINOR__) < 303
    #error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !"
    #endif
    
    #include <inttypes.h>
    #include <avr/pgmspace.h>
    
    /** 
     *  @name  Definitions for MCU Clock Frequency
     *  Adapt the MCU clock frequency in Hz to your target. 
     */
    #define XTAL 8000000              /**< clock frequency in Hz, used to calculate delay timer */
    
    
    /**
     * @name  Definition for LCD controller type
     * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller.
     */
    #define LCD_CONTROLLER_KS0073 0  /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
    
    /** 
     *  @name  Definitions for Display Size 
     *  Change these definitions to adapt setting to your display
     */
    #define LCD_LINES           2     /**< number of visible lines of the display */
    #define LCD_DISP_LENGTH    16     /**< visibles characters per line of the display */
    #define LCD_LINE_LENGTH  0x40     /**< internal line length of the display    */
    #define LCD_START_LINE1  0x00     /**< DDRAM address of first char of line 1 */
    #define LCD_START_LINE2  0x40     /**< DDRAM address of first char of line 2 */
    #define LCD_START_LINE3  0x14     /**< DDRAM address of first char of line 3 */
    #define LCD_START_LINE4  0x54     /**< DDRAM address of first char of line 4 */
    #define LCD_WRAP_LINES      0     /**< 0: no wrap, 1: wrap at end of visibile line */
    
    
    #define LCD_IO_MODE      1         /**< 0: memory mapped mode, 1: IO port mode */
    #if LCD_IO_MODE
    /**
     *  @name Definitions for 4-bit IO mode
     *  Change LCD_PORT if you want to use a different port for the LCD pins.
     *
     *  The four LCD data lines and the three control lines RS, RW, E can be on the 
     *  same port or on different ports. 
     *  Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on
     *  different ports. 
     *
     *  Normally the four data lines should be mapped to bit 0..3 on one port, but it
     *  is possible to connect these data lines in different order or even on different
     *  ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions.
     *  
     */
    #define LCD_PORT         PORTD        /**< port for the LCD lines   */
    #define LCD_DATA0_PORT   LCD_PORT     /**< port for 4bit data bit 0 */
    #define LCD_DATA1_PORT   LCD_PORT     /**< port for 4bit data bit 1 */
    #define LCD_DATA2_PORT   LCD_PORT     /**< port for 4bit data bit 2 */
    #define LCD_DATA3_PORT   LCD_PORT     /**< port for 4bit data bit 3 */
    #define LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
    #define LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
    #define LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */
    #define LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */
    #define LCD_RS_PORT      LCD_PORT     /**< port for RS line         */
    #define LCD_RS_PIN       4            /**< pin  for RS line         */
    #define LCD_RW_PORT      LCD_PORT     /**< port for RW line         */
    #define LCD_RW_PIN       5            /**< pin  for RW line         */
    #define LCD_E_PORT       LCD_PORT     /**< port for Enable line     */
    #define LCD_E_PIN        6            /**< pin  for Enable line     */
    
    #elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || \
          defined(__AVR_ATmega8515__)|| defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || \
          defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__)
    /*
     *  memory mapped mode is only supported when the device has an external data memory interface
     */
    #define LCD_IO_DATA      0xC000    /* A15=E=1, A14=RS=1                 */
    #define LCD_IO_FUNCTION  0x8000    /* A15=E=1, A14=RS=0                 */
    #define LCD_IO_READ      0x0100    /* A8 =R/W=1 (R/W: 1=Read, 0=Write   */
    #else
    #error "external data memory interface not available for this device, use 4-bit IO port mode"
    
    #endif
    
    
    /**
     *  @name Definitions for LCD command instructions
     *  The constants define the various LCD controller instructions which can be passed to the 
     *  function lcd_command(), see HD44780 data sheet for a complete description.
     */
    
    /* instruction register bit positions, see HD44780U data sheet */
    #define LCD_CLR               0      /* DB0: clear display                  */
    #define LCD_HOME              1      /* DB1: return to home position        */
    #define LCD_ENTRY_MODE        2      /* DB2: set entry mode                 */
    #define LCD_ENTRY_INC         1      /*   DB1: 1=increment, 0=decrement     */
    #define LCD_ENTRY_SHIFT       0      /*   DB2: 1=display shift on           */
    #define LCD_ON                3      /* DB3: turn lcd/cursor on             */
    #define LCD_ON_DISPLAY        2      /*   DB2: turn display on              */
    #define LCD_ON_CURSOR         1      /*   DB1: turn cursor on               */
    #define LCD_ON_BLINK          0      /*     DB0: blinking cursor ?          */
    #define LCD_MOVE              4      /* DB4: move cursor/display            */
    #define LCD_MOVE_DISP         3      /*   DB3: move display (0-> cursor) ?  */
    #define LCD_MOVE_RIGHT        2      /*   DB2: move right (0-> left) ?      */
    #define LCD_FUNCTION          5      /* DB5: function set                   */
    #define LCD_FUNCTION_8BIT     4      /*   DB4: set 8BIT mode (0->4BIT mode) */
    #define LCD_FUNCTION_2LINES   3      /*   DB3: two lines (0->one line)      */
    #define LCD_FUNCTION_10DOTS   2      /*   DB2: 5x10 font (0->5x7 font)      */
    #define LCD_CGRAM             6      /* DB6: set CG RAM address             */
    #define LCD_DDRAM             7      /* DB7: set DD RAM address             */
    #define LCD_BUSY              7      /* DB7: LCD is busy                    */
    
    /* set entry mode: display shift on/off, dec/inc cursor move direction */
    #define LCD_ENTRY_DEC            0x04   /* display shift off, dec cursor move dir */
    #define LCD_ENTRY_DEC_SHIFT      0x05   /* display shift on,  dec cursor move dir */
    #define LCD_ENTRY_INC_           0x06   /* display shift off, inc cursor move dir */
    #define LCD_ENTRY_INC_SHIFT      0x07   /* display shift on,  inc cursor move dir */
    
    /* display on/off, cursor on/off, blinking char at cursor position */
    #define LCD_DISP_OFF             0x08   /* display off                            */
    #define LCD_DISP_ON              0x0C   /* display on, cursor off                 */
    #define LCD_DISP_ON_BLINK        0x0D   /* display on, cursor off, blink char     */
    #define LCD_DISP_ON_CURSOR       0x0E   /* display on, cursor on                  */
    #define LCD_DISP_ON_CURSOR_BLINK 0x0F   /* display on, cursor on, blink char      */
    
    /* move cursor/shift display */
    #define LCD_MOVE_CURSOR_LEFT     0x10   /* move cursor left  (decrement)          */
    #define LCD_MOVE_CURSOR_RIGHT    0x14   /* move cursor right (increment)          */
    #define LCD_MOVE_DISP_LEFT       0x18   /* shift display left                     */
    #define LCD_MOVE_DISP_RIGHT      0x1C   /* shift display right                    */
    
    /* function set: set interface data length and number of display lines */
    #define LCD_FUNCTION_4BIT_1LINE  0x20   /* 4-bit interface, single line, 5x7 dots */
    #define LCD_FUNCTION_4BIT_2LINES 0x28   /* 4-bit interface, dual line,   5x7 dots */
    #define LCD_FUNCTION_8BIT_1LINE  0x30   /* 8-bit interface, single line, 5x7 dots */
    #define LCD_FUNCTION_8BIT_2LINES 0x38   /* 8-bit interface, dual line,   5x7 dots */
    
    
    #define LCD_MODE_DEFAULT     ((1<<LCD_ENTRY_MODE) | (1<<LCD_ENTRY_INC) )
    
    
    
    /** 
     *  @name Functions
     */
    
    
    /**
     @brief    Initialize display and select type of cursor
     @param    dispAttr \b LCD_DISP_OFF display off\n
                        \b LCD_DISP_ON display on, cursor off\n
                        \b LCD_DISP_ON_CURSOR display on, cursor on\n
                        \b LCD_DISP_ON_CURSOR_BLINK display on, cursor on flashing             
     @return  none
    */
    extern void lcd_init(uint8_t dispAttr);
    
    
    /**
     @brief    Clear display and set cursor to home position
     @param    void                                        
     @return   none
    */
    extern void lcd_clrscr(void);
    
    
    /**
     @brief    Set cursor to home position
     @param    void                                        
     @return   none
    */
    extern void lcd_home(void);
    
    
    /**
     @brief    Set cursor to specified position
     
     @param    x horizontal position\n (0: left most position)
     @param    y vertical position\n   (0: first line)
     @return   none
    */
    extern void lcd_gotoxy(uint8_t x, uint8_t y);
    
    
    /**
     @brief    Display character at current cursor position
     @param    c character to be displayed                                       
     @return   none
    */
    extern void lcd_putc(char c);
    
    
    /**
     @brief    Display string without auto linefeed
     @param    s string to be displayed                                        
     @return   none
    */
    extern void lcd_puts(const char *s);
    
    
    /**
     @brief    Display string from program memory without auto linefeed
     @param    s string from program memory be be displayed                                        
     @return   none
     @see      lcd_puts_P
    */
    extern void lcd_puts_p(const char *progmem_s);
    
    
    /**
     @brief    Send LCD controller instruction command
     @param    cmd instruction to send to LCD controller, see HD44780 data sheet
     @return   none
    */
    extern void lcd_command(uint8_t cmd);
    
    
    /**
     @brief    Send data byte to LCD controller 
     
     Similar to lcd_putc(), but without interpreting LF
     @param    data byte to send to LCD controller, see HD44780 data sheet
     @return   none
    */
    extern void lcd_data(uint8_t data);
    
    
    /**
     @brief macros for automatically storing string constant in program memory
    */
    #define lcd_puts_P(__s)         lcd_puts_p(PSTR(__s))
    
    /*@}*/
    #endif //LCD_H
    
    
    #endif /* LCD_H_ */
    Die lcd.c
    Code:
    #include <inttypes.h>
    #include <avr/io.h>
    #include <avr/pgmspace.h>
    #include "lcd.h"
    
    
    
    /* 
    ** constants/macros 
    */
    #define DDR(x) (*(&x - 1))      /* address of data direction register of port x */
    #if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__)
        /* on ATmega64/128 PINF is on port 0x00 and not 0x60 */
        #define PIN(x) ( &PORTF==&(x) ? _SFR_IO8(0x00) : (*(&x - 2)) )
    #else
    	#define PIN(x) (*(&x - 2))    /* address of input register of port x          */
    #endif
    
    
    #if LCD_IO_MODE
    #define lcd_e_delay()   __asm__ __volatile__( "rjmp 1f\n 1:" );   //#define lcd_e_delay() __asm__ __volatile__( "rjmp 1f\n 1: rjmp 2f\n 2:" );
    #define lcd_e_high()    LCD_E_PORT  |=  _BV(LCD_E_PIN);
    #define lcd_e_low()     LCD_E_PORT  &= ~_BV(LCD_E_PIN);
    #define lcd_e_toggle()  toggle_e()
    #define lcd_rw_high()   LCD_RW_PORT |=  _BV(LCD_RW_PIN)
    #define lcd_rw_low()    LCD_RW_PORT &= ~_BV(LCD_RW_PIN)
    #define lcd_rs_high()   LCD_RS_PORT |=  _BV(LCD_RS_PIN)
    #define lcd_rs_low()    LCD_RS_PORT &= ~_BV(LCD_RS_PIN)
    #endif
    
    #if LCD_IO_MODE
    #if LCD_LINES==1
    #define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_1LINE 
    #else
    #define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_4BIT_2LINES 
    #endif
    #else
    #if LCD_LINES==1
    #define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_8BIT_1LINE
    #else
    #define LCD_FUNCTION_DEFAULT    LCD_FUNCTION_8BIT_2LINES
    #endif
    #endif
    
    #if LCD_CONTROLLER_KS0073
    #if LCD_LINES==4
    
    #define KS0073_EXTENDED_FUNCTION_REGISTER_ON  0x2C   /* |0|010|1100 4-bit mode, extension-bit RE = 1 */
    #define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x28   /* |0|010|1000 4-bit mode, extension-bit RE = 0 */
    #define KS0073_4LINES_MODE                    0x09   /* |0|000|1001 4 lines mode */
    
    #endif
    #endif
    
    /* 
    ** function prototypes 
    */
    #if LCD_IO_MODE
    static void toggle_e(void);
    #endif
    
    /*
    ** local functions
    */
    
    
    
    /*************************************************************************
     delay loop for small accurate delays: 16-bit counter, 4 cycles/loop
    *************************************************************************/
    static inline void _delayFourCycles(unsigned int __count)
    {
        if ( __count == 0 )    
            __asm__ __volatile__( "rjmp 1f\n 1:" );    // 2 cycles
        else
            __asm__ __volatile__ (
        	    "1: sbiw %0,1" "\n\t"                  
        	    "brne 1b"                              // 4 cycles/loop
        	    : "=w" (__count)
        	    : "0" (__count)
        	   );
    }
    
    
    /************************************************************************* 
    delay for a minimum of <us> microseconds
    the number of loops is calculated at compile-time from MCU clock frequency
    *************************************************************************/
    #define delay(us)  _delayFourCycles( ( ( 1*(XTAL/4000) )*us)/1000 )
    
    
    #if LCD_IO_MODE
    /* toggle Enable Pin to initiate write */
    static void toggle_e(void)
    {
        lcd_e_high();
        lcd_e_delay();
        lcd_e_low();
    }
    #endif
    
    
    /*************************************************************************
    Low-level function to write byte to LCD controller
    Input:    data   byte to write to LCD
              rs     1: write data    
                     0: write instruction
    Returns:  none
    *************************************************************************/
    #if LCD_IO_MODE
    static void lcd_write(uint8_t data,uint8_t rs) 
    {
        unsigned char dataBits ;
    
    
        if (rs) {   /* write data        (RS=1, RW=0) */
           lcd_rs_high();
        } else {    /* write instruction (RS=0, RW=0) */
           lcd_rs_low();
        }
        lcd_rw_low();
    
        if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
          && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) )
        {
            /* configure data pins as output */
            DDR(LCD_DATA0_PORT) |= 0x0F;
    
            /* output high nibble first */
            dataBits = LCD_DATA0_PORT & 0xF0;
            LCD_DATA0_PORT = dataBits |((data>>4)&0x0F);
            lcd_e_toggle();
    
            /* output low nibble */
            LCD_DATA0_PORT = dataBits | (data&0x0F);
            lcd_e_toggle();
    
            /* all data pins high (inactive) */
            LCD_DATA0_PORT = dataBits | 0x0F;
        }
        else
        {
            /* configure data pins as output */
            DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
            DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
            DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
            DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
            
            /* output high nibble first */
            LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
            LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
            LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
            LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
        	if(data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
        	if(data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
        	if(data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
        	if(data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);   
            lcd_e_toggle();
            
            /* output low nibble */
            LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN);
            LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN);
            LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN);
            LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);
        	if(data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
        	if(data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
        	if(data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
        	if(data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
            lcd_e_toggle();        
            
            /* all data pins high (inactive) */
            LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);
            LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);
            LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN);
            LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN);
        }
    }
    #else
    #define lcd_write(d,rs) if (rs) *(volatile uint8_t*)(LCD_IO_DATA) = d; else *(volatile uint8_t*)(LCD_IO_FUNCTION) = d;
    /* rs==0 -> write instruction to LCD_IO_FUNCTION */
    /* rs==1 -> write data to LCD_IO_DATA */
    #endif
    
    
    /*************************************************************************
    Low-level function to read byte from LCD controller
    Input:    rs     1: read data    
                     0: read busy flag / address counter
    Returns:  byte read from LCD controller
    *************************************************************************/
    #if LCD_IO_MODE
    static uint8_t lcd_read(uint8_t rs) 
    {
        uint8_t data;
        
        
        if (rs)
            lcd_rs_high();                       /* RS=1: read data      */
        else
            lcd_rs_low();                        /* RS=0: read busy flag */
        lcd_rw_high();                           /* RW=1  read mode      */
        
        if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
          && ( LCD_DATA0_PIN == 0 )&& (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) )
        {
            DDR(LCD_DATA0_PORT) &= 0xF0;         /* configure data pins as input */
            
            lcd_e_high();
            lcd_e_delay();        
            data = PIN(LCD_DATA0_PORT) << 4;     /* read high nibble first */
            lcd_e_low();
            
            lcd_e_delay();                       /* Enable 500ns low       */
            
            lcd_e_high();
            lcd_e_delay();
            data |= PIN(LCD_DATA0_PORT)&0x0F;    /* read low nibble        */
            lcd_e_low();
        }
        else
        {
            /* configure data pins as input */
            DDR(LCD_DATA0_PORT) &= ~_BV(LCD_DATA0_PIN);
            DDR(LCD_DATA1_PORT) &= ~_BV(LCD_DATA1_PIN);
            DDR(LCD_DATA2_PORT) &= ~_BV(LCD_DATA2_PIN);
            DDR(LCD_DATA3_PORT) &= ~_BV(LCD_DATA3_PIN);
                    
            /* read high nibble first */
            lcd_e_high();
            lcd_e_delay();        
            data = 0;
            if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x10;
            if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x20;
            if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x40;
            if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x80;
            lcd_e_low();
    
            lcd_e_delay();                       /* Enable 500ns low       */
        
            /* read low nibble */    
            lcd_e_high();
            lcd_e_delay();
            if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x01;
            if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x02;
            if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x04;
            if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x08;        
            lcd_e_low();
        }
        return data;
    }
    #else
    #define lcd_read(rs) (rs) ? *(volatile uint8_t*)(LCD_IO_DATA+LCD_IO_READ) : *(volatile uint8_t*)(LCD_IO_FUNCTION+LCD_IO_READ)
    /* rs==0 -> read instruction from LCD_IO_FUNCTION */
    /* rs==1 -> read data from LCD_IO_DATA */
    #endif
    
    
    /*************************************************************************
    loops while lcd is busy, returns address counter
    *************************************************************************/
    static uint8_t lcd_waitbusy(void)
    
    {
        register uint8_t c;
        
        /* wait until busy flag is cleared */
        while ( (c=lcd_read(0)) & (1<<LCD_BUSY)) {}
        
        /* the address counter is updated 4us after the busy flag is cleared */
        delay(2);
    
        /* now read the address counter */
        return (lcd_read(0));  // return address counter
        
    }/* lcd_waitbusy */
    
    
    /*************************************************************************
    Move cursor to the start of next line or to the first line if the cursor 
    is already on the last line.
    *************************************************************************/
    static inline void lcd_newline(uint8_t pos)
    {
        register uint8_t addressCounter;
    
    
    #if LCD_LINES==1
        addressCounter = 0;
    #endif
    #if LCD_LINES==2
        if ( pos < (LCD_START_LINE2) )
            addressCounter = LCD_START_LINE2;
        else
            addressCounter = LCD_START_LINE1;
    #endif
    #if LCD_LINES==4
    #if KS0073_4LINES_MODE
        if ( pos < LCD_START_LINE2 )
            addressCounter = LCD_START_LINE2;
        else if ( (pos >= LCD_START_LINE2) && (pos < LCD_START_LINE3) )
            addressCounter = LCD_START_LINE3;
        else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4) )
            addressCounter = LCD_START_LINE4;
        else 
            addressCounter = LCD_START_LINE1;
    #else
        if ( pos < LCD_START_LINE3 )
            addressCounter = LCD_START_LINE2;
        else if ( (pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4) )
            addressCounter = LCD_START_LINE3;
        else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2) )
            addressCounter = LCD_START_LINE4;
        else 
            addressCounter = LCD_START_LINE1;
    #endif
    #endif
        lcd_command((1<<LCD_DDRAM)+addressCounter);
    
    }/* lcd_newline */
    
    
    /*
    ** PUBLIC FUNCTIONS 
    */
    
    /*************************************************************************
    Send LCD controller instruction command
    Input:   instruction to send to LCD controller, see HD44780 data sheet
    Returns: none
    *************************************************************************/
    void lcd_command(uint8_t cmd)
    {
        lcd_waitbusy();
        lcd_write(cmd,0);
    }
    
    
    /*************************************************************************
    Send data byte to LCD controller 
    Input:   data to send to LCD controller, see HD44780 data sheet
    Returns: none
    *************************************************************************/
    void lcd_data(uint8_t data)
    {
        lcd_waitbusy();
        lcd_write(data,1);
    }
    
    
    
    /*************************************************************************
    Set cursor to specified position
    Input:    x  horizontal position  (0: left most position)
              y  vertical position    (0: first line)
    Returns:  none
    *************************************************************************/
    void lcd_gotoxy(uint8_t x, uint8_t y)
    {
    #if LCD_LINES==1
        lcd_command((1<<LCD_DDRAM)+LCD_START_LINE1+x);
    #endif
    #if LCD_LINES==2
        if ( y==0 ) 
            lcd_command((1<<LCD_DDRAM)+LCD_START_LINE1+x);
        else
            lcd_command((1<<LCD_DDRAM)+LCD_START_LINE2+x);
    #endif
    #if LCD_LINES==4
        if ( y==0 )
            lcd_command((1<<LCD_DDRAM)+LCD_START_LINE1+x);
        else if ( y==1)
            lcd_command((1<<LCD_DDRAM)+LCD_START_LINE2+x);
        else if ( y==2)
            lcd_command((1<<LCD_DDRAM)+LCD_START_LINE3+x);
        else /* y==3 */
            lcd_command((1<<LCD_DDRAM)+LCD_START_LINE4+x);
    #endif
    
    }/* lcd_gotoxy */
    
    
    /*************************************************************************
    *************************************************************************/
    int lcd_getxy(void)
    {
        return lcd_waitbusy();
    }
    
    
    /*************************************************************************
    Clear display and set cursor to home position
    *************************************************************************/
    void lcd_clrscr(void)
    {
        lcd_command(1<<LCD_CLR);
    }
    
    
    /*************************************************************************
    Set cursor to home position
    *************************************************************************/
    void lcd_home(void)
    {
        lcd_command(1<<LCD_HOME);
    }
    
    
    /*************************************************************************
    Display character at current cursor position 
    Input:    character to be displayed                                       
    Returns:  none
    *************************************************************************/
    void lcd_putc(char c)
    {
        uint8_t pos;
    
    
        pos = lcd_waitbusy();   // read busy-flag and address counter
        if (c=='\n')
        {
            lcd_newline(pos);
        }
        else
        {
    #if LCD_WRAP_LINES==1
    #if LCD_LINES==1
            if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
                lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
            }
    #elif LCD_LINES==2
            if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
                lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);    
            }else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ){
                lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
            }
    #elif LCD_LINES==4
            if ( pos == LCD_START_LINE1+LCD_DISP_LENGTH ) {
                lcd_write((1<<LCD_DDRAM)+LCD_START_LINE2,0);    
            }else if ( pos == LCD_START_LINE2+LCD_DISP_LENGTH ) {
                lcd_write((1<<LCD_DDRAM)+LCD_START_LINE3,0);
            }else if ( pos == LCD_START_LINE3+LCD_DISP_LENGTH ) {
                lcd_write((1<<LCD_DDRAM)+LCD_START_LINE4,0);
            }else if ( pos == LCD_START_LINE4+LCD_DISP_LENGTH ) {
                lcd_write((1<<LCD_DDRAM)+LCD_START_LINE1,0);
            }
    #endif
            lcd_waitbusy();
    #endif
            lcd_write(c, 1);
        }
    
    }/* lcd_putc */
    
    
    /*************************************************************************
    Display string without auto linefeed 
    Input:    string to be displayed
    Returns:  none
    *************************************************************************/
    void lcd_puts(const char *s)
    /* print string on lcd (no auto linefeed) */
    {
        register char c;
    
        while ( (c = *s++) ) {
            lcd_putc(c);
        }
    
    }/* lcd_puts */
    
    
    /*************************************************************************
    Display string from program memory without auto linefeed 
    Input:     string from program memory be be displayed                                        
    Returns:   none
    *************************************************************************/
    void lcd_puts_p(const char *progmem_s)
    /* print string from program memory on lcd (no auto linefeed) */
    {
        register char c;
    
        while ( (c = pgm_read_byte(progmem_s++)) ) {
            lcd_putc(c);
        }
    
    }/* lcd_puts_p */
    
    
    /*************************************************************************
    Initialize display and select type of cursor 
    Input:    dispAttr LCD_DISP_OFF            display off
                       LCD_DISP_ON             display on, cursor off
                       LCD_DISP_ON_CURSOR      display on, cursor on
                       LCD_DISP_CURSOR_BLINK   display on, cursor on flashing
    Returns:  none
    *************************************************************************/
    void lcd_init(uint8_t dispAttr)
    {
    #if LCD_IO_MODE
        /*
         *  Initialize LCD to 4 bit I/O mode
         */
         
        if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
          && ( &LCD_RS_PORT == &LCD_DATA0_PORT) && ( &LCD_RW_PORT == &LCD_DATA0_PORT) && (&LCD_E_PORT == &LCD_DATA0_PORT)
          && (LCD_DATA0_PIN == 0 ) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) 
          && (LCD_RS_PIN == 4 ) && (LCD_RW_PIN == 5) && (LCD_E_PIN == 6 ) )
        {
            /* configure all port bits as output (all LCD lines on same port) */
            DDR(LCD_DATA0_PORT) |= 0x7F;
        }
        else if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT )
               && (LCD_DATA0_PIN == 0 ) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) )
        {
            /* configure all port bits as output (all LCD data lines on same port, but control lines on different ports) */
            DDR(LCD_DATA0_PORT) |= 0x0F;
            DDR(LCD_RS_PORT)    |= _BV(LCD_RS_PIN);
            DDR(LCD_RW_PORT)    |= _BV(LCD_RW_PIN);
            DDR(LCD_E_PORT)     |= _BV(LCD_E_PIN);
        }
        else
        {
            /* configure all port bits as output (LCD data and control lines on different ports */
            DDR(LCD_RS_PORT)    |= _BV(LCD_RS_PIN);
            DDR(LCD_RW_PORT)    |= _BV(LCD_RW_PIN);
            DDR(LCD_E_PORT)     |= _BV(LCD_E_PIN);
            DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN);
            DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN);
            DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN);
            DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN);
        }
        delay(16000);        /* wait 16ms or more after power-on       */
        
        /* initial write to lcd is 8bit */
        LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN);  // _BV(LCD_FUNCTION)>>4;
        LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN);  // _BV(LCD_FUNCTION_8BIT)>>4;
        lcd_e_toggle();
        delay(4992);         /* delay, busy flag can't be checked here */
       
        /* repeat last command */ 
        lcd_e_toggle();      
        delay(64);           /* delay, busy flag can't be checked here */
        
        /* repeat last command a third time */
        lcd_e_toggle();      
        delay(64);           /* delay, busy flag can't be checked here */
    
        /* now configure for 4bit mode */
        LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN);   // LCD_FUNCTION_4BIT_1LINE>>4
        lcd_e_toggle();
        delay(64);           /* some displays need this additional delay */
        
        /* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */    
    #else
        /*
         * Initialize LCD to 8 bit memory mapped mode
         */
        
        /* enable external SRAM (memory mapped lcd) and one wait state */        
        MCUCR = _BV(SRE) | _BV(SRW);
    
        /* reset LCD */
        delay(16000);                           /* wait 16ms after power-on     */
        lcd_write(LCD_FUNCTION_8BIT_1LINE,0);   /* function set: 8bit interface */                   
        delay(4992);                            /* wait 5ms                     */
        lcd_write(LCD_FUNCTION_8BIT_1LINE,0);   /* function set: 8bit interface */                 
        delay(64);                              /* wait 64us                    */
        lcd_write(LCD_FUNCTION_8BIT_1LINE,0);   /* function set: 8bit interface */                
        delay(64);                              /* wait 64us                    */
    #endif
    
    #if KS0073_4LINES_MODE
        /* Display with KS0073 controller requires special commands for enabling 4 line mode */
    	lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON);
    	lcd_command(KS0073_4LINES_MODE);
    	lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF);
    #else
        lcd_command(LCD_FUNCTION_DEFAULT);      /* function set: display lines  */
    #endif
        lcd_command(LCD_DISP_OFF);              /* display off                  */
        lcd_clrscr();                           /* display clear                */ 
        lcd_command(LCD_MODE_DEFAULT);          /* set entry mode               */
        lcd_command(dispAttr);                  /* display/cursor control       */
    
    }/* lcd_init */
    nun der Text für die Maindatei:
    Code:
    #include <avr/io.h>
    
    #define F_CPU 8000000UL 
    #ifndef F_CPU
    #warning "F_CPU war noch nicht definiert, wird nun mit 8000000 definiert"
    #define F_CPU 8000000UL    
    #endif
    #include <util/delay.h>
    #include "lcd.h"
    
    
    int main(void)
    {
    	lcd_init(LCD_DISP_ON_BLINK);
    	lcd_gotoxy(0,0);
    	lcd_putc('T');
    	_delay_ms(1000);
    	lcd_gotoxy(0,1);
    	lcd_puts("Test Line 1");
    	_delay_ms(2000);
    	lcd_clrscr();
    }
    Wenn ich die Spannungsversorgung herstelle dann zeigt das Display nur in der ersten Zeile ein Balken an.
    Frage:
    Bei Reichelt steht das es sich um einen KS0066U handelt, bei dem Datenblatt, welches bei Reichelt im Anhang zu finden ist steht jedoch das es sich dort um den KS0070B handelt. Im Internet habe ich gefunden das beide mit dem HD44780U kompatibel sind.

    Beim kompilieren kommt folgende Fehlermeldung:
    c:\program files (x86)\atmel\avr studio 5.0\avr toolchain\bin\../lib/gcc/avr/4.5.1/../../../../avr/include/util/delay.h(94,3): #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"

    Programmiert wird mit dem AVRStudio5

    kann mir irgendwer sagen wieso ich mein Display nicht bespielen kann woran es liegt oder hat wer ein Fehler gefunden? viel Hilfe bin ich sehr Dankbar
    Grus aus Hamburg

  2. #2
    Erfahrener Benutzer Fleißiges Mitglied Avatar von Thorben W
    Registriert seit
    17.02.2012
    Ort
    Niedersachsen
    Beiträge
    108
    Hallo robotka,
    ich habe auch ein Display von Reichelt mit diesem Kontroller aber für den RP6.
    Das Display hat 4x16 Zeichen
    Ich kenne mich mit deiner Programmierung nicht aus, aber ich poste dir mal die bei mir funktionierende Libteile:
    lcd.c
    Code:
    // LCD
    // All LCD routines are prepared to control a 2x16 character LCD.
    // If you want to connect a bigger LCD you need to change some things in 
    // these routines! (especially in the initLCD, setCursorLCD and showScreenLCD
    // routines)
    
    char lcd_tmp_buffer[17];
    
    
    /**
     * Sets the LCD ports without affecting the LEDs and also pulses the
     * enable line of the LCD to 'inform' the LCD about the new data.
     *
     */
    void setLCDD(uint8_t lcdd)
    {
    	PORTA = lcdd; 
    	sleep(5);
    	PORTG |= DISP_EN_RD;
    	delayCycles(150);
    	PORTG &= ~DISP_EN_RD;
    	delayCycles(20);
    }
    
    /**
     * Write a command to the LCD.
     */
    void writeLCDCommand(uint8_t cmd)
    {
    	PORTG &= ~DISP_RS_ALE;
    	setLCDD(cmd);
    	delayCycles(500);
    }
    
    /**
     * Initialize the LCD. Always call this before using the LCD! 
     *
     */
    void initLCD(void)
    {
    	delayCycles(34000);  //No need for Power ON delay as usually the
    	// Bootloader should have been executed before...
    	PORTG &= ~DISP_WR;
    	PORTG &= ~DISP_RS_ALE;
    	PORTG &= ~DISP_EN_RD;
    	
    	mSleep(5);
    	
    	writeLCDCommand(0b00110000);
    	delayCycles(55500);
    	mSleep(50);
    	
    	writeLCDCommand(0b00110000);
    	delayCycles(55500);
    	mSleep(5);
    	
    	writeLCDCommand(0b00110000);
    	delayCycles(55500);
    	
    	mSleep(5);
    	
    	writeLCDCommand(0b00111000);
    	delayCycles(55500);
    	mSleep(1);
    	
    	writeLCDCommand(0b00001000);
    	delayCycles(55500);
    	mSleep(1);
    	
    	writeLCDCommand(0b00000001);
    	delayCycles(55500);
    	mSleep(1);
    	
    	writeLCDCommand(0b00000010);
    	delayCycles(55500);
    	mSleep(1);
    		
    	writeLCDCommand(0b00001100);
    	delayCycles(55500);
    	mSleep(1);
    
    	mSleep(5);
    	
    	clearLCD();
    }
    
    
    /**
     * Clears the whole LCD!
     */
    void clearLCD(void)
    {
    	writeLCDCommand(0b00000001);
    	delayCycles(5500);
    }
    
    
    /**
     * Write a single character to the LCD.
     *
     * Example:
     *
     *			writeCharLCD('R');
     *			writeCharLCD('P');
     *			writeCharLCD('6');
     *			writeCharLCD(' ');
     *			writeCharLCD('0');
     *			writeCharLCD(48); // 48 is ASCII code for '0'
     *			writeCharLCD(49); // '1'
     *			writeCharLCD(50); // '2'
     *			writeCharLCD(51); // '3'
     *			//...
     *
     *			would output:
     *			RP6 00123
     *			at the current cursor position!
     *			use setCursorPos function to move the cursor to a 
     *			different location!
     */
    void writeCharLCD(uint8_t ch)
    {
    	PORTG |= DISP_RS_ALE;
    	setLCDD(ch);
    	delayCycles(50);
    }
    
    
    /**
     * Writes a null terminated string from flash program memory to the LCD.
     * You can use the macro writeStringLCD_P(STRING); instead, this macro
     * ensures that the String is stored in program memory only!
     *
     * Example:
     *
     *			writeNStringLCD_P(PSTR("RP6 Control"));
     *
     *			// There is also a Macro that makes life easier and
     *			// you can simply write:
     *			writeStringLCD_P("RP6 Control");
     *
     */
    void writeNStringLCD_P(const char *pstring)
    {
        uint8_t c;
        for (;(c = pgm_read_byte_near(pstring++));writeCharLCD(c));
    }
    
    /**
     * Writes a String from SRAM to the LCD.
     */
    void writeStringLCD(char *string)
    {
    	while(*string)
    		writeCharLCD(*string++);
    }
    
    /**
     * Writes a string with specified length and offset from SRAM to the LCD.
     * If it is a null terminated string, output will be stopped at the
     * end. It does not need to be null terminated, but it is recommended
     * to use only null terminated strings/buffers, otherwise the function could
     * output any SRAM memory data stored after the string until it reaches a 0
     * or the specified length!
     *
     * Example:
     *
     *			writeStringLength("RP6 Robot Sytem",16,0);
     *			// would output: "RP6 Robot Sytem\n"
     *			writeStringLength("RP6 Robot Sytem",11,4);
     *			// would output: "Robot System"
     * 			writeStringLength("RP6 Robot Sytem",40,4);
     *			// would output: "Robot System"
     *			// No matter if the specified length is 40 characters!
     *
     */
    void writeStringLengthLCD(char *string, uint8_t length, uint8_t offset)
    {
    	for(string = &string[offset]; *string && length; length--)
    		writeCharLCD(*string++);
    }
    
    /**
     * Write a number (with specified base) to the LCD.
     *
     * Example:
     *
     *			// Write a hexadecimal number to the LCD:
     *			writeInteger(0xAACC,16);
     *			// Instead of 16 you can also write "HEX" as this is defined in the
     *			// RP6RobotBaseLib.h :
     *			writeInteger(0xAACC, HEX);
     *			// Other Formats:
     *			writeInteger(1024,DEC);  	// Decimal
     *			writeInteger(511,OCT);		// Ocal
     *			writeInteger(0b11010111,BIN); // Binary
     */
    void writeIntegerLCD(int16_t number, uint8_t base)
    {
    	itoa(number, &lcd_tmp_buffer[0], base);
    	writeStringLCD(&lcd_tmp_buffer[0]);
    }
    
    /**
     * Same as writeInteger, but with defined length.
     * This means this routine will add leading zeros to the number if length is
     * larger than the actual value or cut the upper digits if length is smaller
     * than the actual value.
     *
     * Example:
     *
     *			// Write a hexadecimal number to the LCD:
     *			writeIntegerLength(0xAACC, 16, 8);
     *			// Instead of 16 you can also write "HEX" as this is defined in the
     *			// RP6ControlLib.h :
     *			writeIntegerLength(0xAACC, HEX, 8);
     *			// Other Formats:
     *			writeIntegerLength(1024,DEC,6);  	// Decimal
     *			writeIntegerLength(511,OCT,4);		// Ocal
     *			writeIntegerLength(0b11010111,BIN,8); // Binary
     */
     
    void writeIntegerLengthLCD(int16_t number, uint8_t base, uint8_t length)
    {
    	char buffer[17];
    	itoa(number, &buffer[0], base);
    	int8_t cnt = length - strlen(buffer);
    	if(cnt > 0) {
    		for(; cnt > 0; cnt--, writeCharLCD('0'));
    		writeStringLCD(&buffer[0]);
    	}
    	else 
    		writeStringLengthLCD(&buffer[0],length,-cnt);
    }
    
    /**
     * This function is useful for displaying text screens on the LCD.
     * It clears the whole LCD and writes the two Strings to line 1 and
     * line 2.
     */
    void _showScreenLCD_P(const char *line1, const char *line2, const char *line3, const char *line4)
    {
    	clearLCD();
    	setCursorPosLCD(0, 0);
    	writeNStringLCD_P(line1);
    	setCursorPosLCD(1, 0);
    	writeNStringLCD_P(line2);
    	setCursorPosLCD(2, 0);
    	writeNStringLCD_P(line3);
    	setCursorPosLCD(3, 0);
    	writeNStringLCD_P(line4);
    }
    
    /**
     * Sets the cursor position on LCD.
     */
    void setCursorPosLCD(uint8_t line, uint8_t pos)
    {
    	//pos |= 248;					//128
    	if(line==0) pos += 0b0010000000;
    	if(line==1) pos += 0b0010101000;
    	if(line==2) pos += 0b0010010000;		//pos += 0x10
    	if(line==3) pos += 0b0011010000;
    	writeLCDCommand(pos);
    }
    
    /**
     * Clears some characters after the given position.
     */
    void clearPosLCD(uint8_t line, uint8_t pos, uint8_t length)
    {
    	setCursorPosLCD(line,pos);
    	while(length--)
    		writeCharLCD(' ');
    }
    lcd.h
    Code:
    // LCD:
    
    void setLCDD(uint8_t lcdd);
    void writeLCDCommand(uint8_t cmd);
    void initLCD(void);
    
    void clearLCD(void);
    void clearPosLCD(uint8_t line, uint8_t pos, uint8_t length);
    void writeCharLCD(uint8_t ch);
    #define writeStringLCD_P(__pstr) writeNStringLCD_P((PSTR(__pstr)))
    void writeStringLengthLCD(char *string, uint8_t length, uint8_t offset);
    void writeStringLCD(char *string);
    void writeNStringLCD_P(const char *pstring);
    
    void _showScreenLCD_P(const char *line1, const char *line2, const char *line3, const char *line4);
    
    #define showScreenLCD(__line1,__line2,__line3,__line4); ({_showScreenLCD_P((PSTR(__line1)),(PSTR(__line2)),(PSTR(__line3)),(PSTR(__line4)));})
    
    #ifndef HEX
    	#define HEX 16
    #endif
    #ifndef DEC 
    	#define DEC 10
    #endif
    #ifndef OCT
    	#define OCT 8
    #endif
    #ifndef BIN
    	#define BIN 2
    #endif
    void writeIntegerLCD(int16_t number, uint8_t base);
    void writeIntegerLengthLCD(int16_t number, uint8_t base, uint8_t length);
    
    void setCursorPosLCD(uint8_t line, uint8_t pos);
    Das ist die geänderte RP6 Orginallib
    Ich hoffe dir helfen zu können
    Thorben

  3. #3
    Erfahrener Benutzer Robotik Visionär Avatar von 021aet04
    Registriert seit
    17.01.2005
    Ort
    Niklasdorf
    Alter
    36
    Beiträge
    5.056
    Die Balken bedeuten das das LCD nicht bzw falsch initialisiert wurde (eventuell passt auch die Beschaltung nicht, Ader vertauscht, im 4bit Modus die nicht benötigen Eingänge auf Masse gelegt,...).

    Die Fehlermeldung bezieht sich auf die delay.h
    Du hast die Optimierung ausgeschaltet und dadurch gibt es Fehler mit der delay.h (funktioniert nicht wie gewollt => won't work as designed)

    MfG Hannes

  4. #4
    Neuer Benutzer Öfters hier
    Registriert seit
    22.03.2013
    Beiträge
    6
    Hallo das es sich um die delay handelt war mir klar nur halt nicht warum. verstehe es nicht, denn ich habe mit #define F_CPU 8000000UL die Frequenz definiert... wie kann man denn die Optimierung einschalten?
    und verdrahtungsfehler sind ausgeschlossen habe alles 5 mal genau geprüft und ist ja auch direkt mit Leitungen angeschlossen.... die 4 Datenleitungen also vom Display Data5-Data8 habe ich nicht auf Masse gelegt kann es nur daran liegen??
    @ Thorben danke werde aber erstmal die gewählte lib nehmen, da sie ja doch häufig verbreitet ist und wenn sie mal funktionieren sollte sehr flexibel ist. Dennoch danke für ne schnelle Antwort

  5. #5
    Erfahrener Benutzer Robotik Visionär Avatar von 021aet04
    Registriert seit
    17.01.2005
    Ort
    Niklasdorf
    Alter
    36
    Beiträge
    5.056
    Du hast einige sinnlose Zeilen im Programm.
    Du schreibst #define F_CPU... und danach steht #ifndef ...
    Das bedeutet:
    Setzte F_CPU
    Wenn F_CPU nicht gesetzt
    setze F_CPU

    Entweder du entfernst dein erstes #define F_CPU oder entfernst #ifndef... bis #endif
    Das ist zwar kein Fehler, ist aber Sinnlos. Du kannst aber auch bei den Einstellungen (Beim AVR Studio 4 hat es Project Options geheißen, wie es beim 5er heißt weiß ich nicht) die Taktfrequenz einstellen, dann wird es automatisch im Makefile eingetragen (dann brauchst du das ganze #ifndef F_CPU... nicht). Dort kannst du auch optimization (das ist der Punkt den du brauchst) einstellen und noch weitere Dinge die mit dem Projekt zutun haben. Was du einstellen musst kannst du normalerweise in der Hilfe bzw im Internet nachlesen. Ich habe beim 4rer "Os" eingestellt und hatte noch nie Probleme.

    MfG Hannes

    MfG Hannes

  6. #6
    Erfahrener Benutzer Robotik Visionär Avatar von Hubert.G
    Registriert seit
    14.10.2006
    Ort
    Pasching OÖ
    Beiträge
    6.220
    #define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */
    Du solltest hier eine 1 hinschreiben, also für einen KS0073
    Die freien Datenleitung musst du nicht auf Masse legen, die haben interne PullUp.
    Grüsse Hubert
    ____________

    Meine Projekte findet ihr auf schorsch.at

  7. #7
    Hallo robotka,

    ich verwende das LED 204B LED von Reichelt, also auch ein LCD mit KS0070B-Controller. Angesteuert wird es auch mit der .lib von Peter Fleury.

    Zu Anfang hatte ich ähnliche Probleme. Bin auch wie Hannes der Meinung, dass es sich um ein Problem bei der Initialisierung handelt.

    Das #define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */ habe ich bei mir auf 0 gelassen. Die Ansteuerung funktioniert. Wenn ich das richtig sehe, ist das nur für ein "extended function register" von Bedeutung.

    Das Problem bei mir war ein Timing-Problem. So habe ich für Taktfrequenzen unter 4Mhz in die Funktion "toggle e" ein delay(40) eingeschoben. Den Wert habe ich durch Ausprobieren gefunden, in wie weit der nun tatsächlich optimal ist, kann ich nicht wirklich sagen.

    Wenn Du schreibst, dass Du den ATMega ohne Quarz verwendest, dann läuft der doch mit einer Taktfrequenz von 1Mhz, oder nicht? Bin mir jetzt nicht so sicher, weil ich nie ohne Quarz gearbeitet habe. Diese Taktfrequenz muss dann auch so angegeben werden, Du gibst im Programm die Taktfrequenz aber mit 8Mhz an. Auch das spricht eher für ein Timingproblem.

    Zunächst solltst Du aber das Problem mit der Fehlermeldung lösen, dass die delay(ms) Funktion tatsächlich auch läuft und das macht was sie soll. Ich verwende die WinAVR Toolschain und habe da im Makefile als Optimization level s (optimize for size) gewählt.

    Viele Grüße

    Uwe
    Legasteniker on Board!
    gefundene Rechtschreibfehler dienen der Belustigung des Lesers und dürfen von diesem behalten werden.

  8. #8
    Erfahrener Benutzer Robotik Visionär Avatar von 021aet04
    Registriert seit
    17.01.2005
    Ort
    Niklasdorf
    Alter
    36
    Beiträge
    5.056
    Die Atmegas bzw Attinys haben (soweit ich weiß) alle einen internen 8MHz RC-Oszillator, der Standardmäßig auf 1MHz heruntergeteilt wird (mit dem Fusebit CKDIV8 o.Ä. je nach Typ). Wenn man das Fusebit für die Teilung entfernt taktet der µC mit den 8MHz, das kann also schon einmal stimmen. Ich verwende meistens den internen Oszillator mit den 8MHz (ohne Teilung durch .

    Ich habe eine Lib für den R8C (Renesas) auf den Atmega umgeschrieben, könnte nachschauen wegen dem Timing. Die Lib funktioniert nur mit delays (ohne Interrupts), die habe ich aber am Laptop.

    MfG Hannes

  9. #9
    Neuer Benutzer Öfters hier
    Registriert seit
    22.03.2013
    Beiträge
    6
    Also nun hatte ich endlich mal zeit mich wieder damit zu beschäftigen jedoch ohne Erfolg....
    Natürlich hab eich nochmal die Pinbelegung kontrolliert Fehler kann ich dort echt 100% ausschließen...

    Ich habe die Fehlermeldung durch Eure hilfe weg bekommen und habe wie empfohlen Optimization auf Os gestellt.
    Der Atmega läuft ohne Quarz auf 8MHz dies habe ich durch die Fuses Eingestellt und auch wieder auslesen lassen, somit denke ich mal stimmt es auch und ich kann diesen Fehler auch ausschließen.

    Nun verstehe ich nicht wieso es nicht funktioniert ich habe ehrlich keine Idee mehr...
    Ich stelle euch zur weiteren Analyse mal den Text vom Complier zur Verfügung:

    Code:
    ------ Build started: Project: Mega8Testfunktionen, Configuration: Debug AVR ------
    Build started.
    Project "Mega8Testfunktionen.avrgccproj" (default targets):
    Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
    Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\AVR Studio 5.0\Vs\AvrGCC.targets" from project "C:\Users\Christian Dopatka\Documents\AVRStudio\Mega8Testfunktionen\Mega8Testfunktionen\Mega8Testfunktionen.avrgccproj" (target "Build" depends on it):
    	Task "RunAvrGCC"
    		C:\Program Files (x86)\Atmel\AVR Studio 5.0\AVR ToolChain\bin\make.exe all 
    Mega8Testfunktionen.c
    		Invoking: AVR/GNU C Compiler
    		"C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -funsigned-char -funsigned-bitfields -Os -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99  -mmcu=atmega8   -MD -MP -MF"Mega8Testfunktionen.d" -MT"Mega8Testfunktionen.d" -o"Mega8Testfunktionen.o" ".././Mega8Testfunktionen.c"
    		Finished building: .././Mega8Testfunktionen.c
    		Building target: Mega8Testfunktionen.elf
    		Invoking: AVR/GNU C/C++ Linker
    		"C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe"  -mmcu=atmega8  -Wl,-Map=Mega8Testfunktionen.map -o Mega8Testfunktionen.elf  lcd.o Mega8Testfunktionen.o  
    		Finished building target: Mega8Testfunktionen.elf
    		"C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  "Mega8Testfunktionen.elf" "Mega8Testfunktionen.hex"
    		"C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objdump.exe" -h -S "Mega8Testfunktionen.elf" > "Mega8Testfunktionen.lss"
    		"C:/Program Files (x86)/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "Mega8Testfunktionen.elf" "Mega8Testfunktionen.eep" || exit 0
    		AVR Memory Usage
    		----------------
    		Device: atmega8
    		Program:     554 bytes (6.8% Full)
    		(.text + .data + .bootloader)
    		Data:         12 bytes (1.2% Full)
    		(.data + .bss + .noinit)
    	Done executing task "RunAvrGCC".
    Done building target "CoreBuild" in project "Mega8Testfunktionen.avrgccproj".
    Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
    Target "Build" in file "C:\Program Files (x86)\Atmel\AVR Studio 5.0\Vs\Avr.common.targets" from project "C:\Users\Christian Dopatka\Documents\AVRStudio\Mega8Testfunktionen\Mega8Testfunktionen\Mega8Testfunktionen.avrgccproj" (entry point):
    Done building target "Build" in project "Mega8Testfunktionen.avrgccproj".
    Done building project "Mega8Testfunktionen.avrgccproj".
    
    Build succeeded.
    ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

  10. #10
    Hallo robotka,

    zu der Ausgabe vom AVR-Studio kann ich leider nichts kompetentes beitragen, da ich wie gesagt die GCC-Toolchain verwendet.

    Vielleicht hilft Dir aber ein kleines Programm weiter, dass ich geschrieben habe um die Fehlerquellen bei meinem ähnlichen Problem ein zu kreisen

    Code:
    /*-------+---------+---------+---------+---------+---------+---------+---------+
    *
    *    Datei:        LCD-Test1.c
    *     erstellt:    im Januar 2010
    *    von:        Bot-Builder
    *
    *    Hardware:    Bot-Board ATMega 16 V2
    *                ATMega 32 und 7,3728 Mhz,
    *                Bot-Board LC-Display V1,
    *                Bot-Board Portanzeige mit LED
    *
    *    Resourcen
    *
    *    Timer0:        frei
    *
    *    Timer1:        frei
    *
    *    Timer2:        frei
    *
    *
    *    Interrupt:    keine
    *
    *    I/O-Pins:
    *
    *
    *    Funktionsbeschreibung:
    *        In diesem Programm wird die vollständige  Initialisierung des
    *        LC-Display ohne Verwendung von Biblotheken abgearbeitet.
    *        Zum Debuggen wurden Verzögerungen verwendet.
    *        Das LC-Display ist wie folgt angeschlossen:
    *            PC0        DB7
    *            PC1        DB6
    *            PC2        DB5
    *            PC3        DB4
    *                    DB3        an gnd
    *                    DB2        an gnd
    *                    DB1        an gnd
    *                    DB0        an gnd
    *            PC4        Enable Hintergrundbeleuchtung
    *            PC5        E (Taktleitung)
    *            PC6        R/W
    *            PC7        RS
    *
    *        Zur Kontrolle werden auf Port D die gleichen Daten ausgegeben
    *        und mit den LEDs dargestellt.
    *
    *        Das Display wird somit im 4-Bit Modus verwendet.
    *
    *        JTAG Interface mit den Fuses ausgeschaltet!
    *        sonst funktioniert Port C nicht vollständig.
    *
    *        Bei dieser Beschaltung kann das Busyflag ausgelesen werden!
    *
    *
    *
    *    Bemerkungen:  
    * 
    *
    *    letzte Änderung: 25.01.2010
    *
    *
    ---------+---------+---------+---------+---------+---------+---------+---------+*/
    
    
    /*-------+---------+---------+---------+---------+---------+---------+---------+
    *   #include-Dateien
    *--------+---------+---------+---------+---------+---------+---------+---------+*/
    #include <avr/io.h>
    #include <util/delay.h>        // definiert _delay_ms() 
    
    
    /*-------+---------+---------+---------+---------+---------+---------+---------+
    *   Variablen.- und Konstantendefintionen
    *--------+---------+---------+---------+---------+---------+---------+---------+*/
    #define delay(us)  _delay_loop_2 (((F_CPU/4000)*us)/1000)        // wartet µs
    
    #define Pause1 50
    #define Pause2 50
    
    /*-------+---------+---------+---------+---------+---------+---------+---------+
    *   Interrupts
    *--------+---------+---------+---------+---------+---------+---------+---------+*/
    //  hier keine
    
    
    /*-------+---------+---------+---------+---------+---------+---------+---------+
    *   Funktionen():
    *--------+---------+---------+---------+---------+---------+---------+---------+*/
    /*-------+---------+---------+---------+---------+---------+---------+---------+
    *   delay_ms(ms):
    *        wartet ms Millisekunden
    *--------+---------+---------+---------+---------+---------+---------+---------+*/
    void delay_ms(uint16_t ms)
    {
      for(uint16_t t=0; t<=ms; t++)
        _delay_ms(1); 
    }
    
    
    
    /*-------+---------+---------+---------+---------+---------+---------+---------+
    *   main()
    ---------+---------+---------+---------+---------+---------+---------+---------+*/
    int main()
    {
        //    Initialiserung
        //    der Ports
        //    alle Pins als Ausgang
        //    also im Datenrichtungsregister an allen Stelle eine Eins
        //    DDRC |= ( (1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3) | (1 << DDC4) | (1 << DDC5) | (1 << DDC6) | (1 << DDC7) ); 
        DDRC = 0xff;
        DDRD = 0xff;
        
        //    alle Ausgänge auf low
        PORTC = 0x00;
        PORTB = 0x00;
        //    Warten damit die Flanke sicher alle fallen
        //    laut Datenblatt reichen 15ms nach erreichen 
        //    der Arbeitsspannung von 4,5V aus
        delay_ms(100);
        
    
        //    Initialisierung des LC-Displays
        //    zunächst in den 8-Bit Modus schalten
        //    DB7 = 0, DB6 = 0 und DB5 = 1
        //    schaltet in die Funktionsdefinition um,
        //    dann bedeutet
        //    DB4 = 1, 8-Bit-Modus
        //    DB3 bis DB0 liegen fest auf gnd
        //    zunächst also die Daten ans LC-Display legen, RS und R/W bleiben null
        //    also PC2 und PC3 auf high
        //    also muss 0b 0000 1100
        //    (mit RS und R/W = 0)
        //    übertragen werden
        
        //    vereinfacht geschrieben
        PORTC = 0x0c;
        PORTD = 0x0c;
    
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    und noch eine Verzögerung weil Busy hier noch nicht
        //    ausgewertet werden kann
        delay_ms(5);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    das Ganze zur Sicherheit noch zwei Mal wiederholen
        //    erste Wiederholung
        //    vereinfacht geschrieben
        PORTC = 0x0c;
        PORTD = 0x0c;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    zweite Wiederholung
        //    vereinfacht geschrieben
        PORTC = 0x0c;
        PORTD = 0x0c;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        
        //    und jetzt in den 4-Bit-Modus schalten
        //    also DB5 = 1 und DB4 = 0
        //    also PC2 = 1 und PC3 = 0
        //    also 0b 0000 0100
        //    mit RS und R/W = 0
        //    vereinfacht geschrieben
        PORTC = 0x04;
        PORTD = 0x04;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    die übrigen Betriebsparameter einstellen
    
    
        //    Funktionsdefinition        0b 001
        //    4-Bit                          0
        //    2/4zeiliges Display                1
        //    5x7 Dots Zeichen                 0
        //    unerheblich                       00
        //    also                    0b 0010 1000
        //    muss übertragen werden
        
        //    zunächst das höherwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        //    Befehl schreiben
        //    also R/W = 0, RS = 0
        //    also PC6 = 0, PC7 = 0
        
        //    vereinfachte Schreibweise
        PORTC = 0x02;
        PORTD = 0x02;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    zunächst das niederwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        
        //    vereinfachte Schreibweise
        PORTC = 0x08;
        PORTD = 0x08;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
    
        //    Display/Cursor            0b 0000 1
        //    Display an                         1
        //    Cursor an                          1
        //    Cursor blinken                       1
        //    also                    0b 0000 1111
        //    muss übertragen werden
        
        //    zunächst das höherwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        //    Befehl schreiben
        //    also R/W = 0, RS = 0
        //    also PC6 = 0, PC7 = 0
        
        //    vereinfachte Schreibweise
        PORTC = 0x00;
        PORTD = 0x00;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    zunächst das niederwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        
        //    vereinfachte Schreibweise
        PORTC = 0x0f;
        PORTD = 0x0f;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
    
    
        //    Modus festlegen                    0b 0000 01
        //    Cursorposition inkrementieren              1
        //    Displayinhalt fest, Cursor schieben           1
        //    also                    0b 0000 0111
        //    muss übertragen werden
        
        //    zunächst das höherwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        //    Befehl schreiben
        //    also R/W = 0, RS = 0
        //    also PC6 = 0, PC7 = 0
        
        //    vereinfachte Schreibweise
        PORTC = 0x00;
        PORTD = 0x00;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    zunächst das niederwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        
        //    vereinfachte Schreibweise
        PORTC = 0x07;
        PORTD = 0x07;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
    
        //    Display löschen                    0b 0000 0001
        //    muss übertragen werden
        
        //    zunächst das höherwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        //    Befehl schreiben
        //    also R/W = 0, RS = 0
        //    also PC6 = 0, PC7 = 0
        
        //    vereinfachte Schreibweise
        PORTC = 0x00;
        PORTD = 0x00;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    zunächst das niederwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        
        //    vereinfachte Schreibweise
        PORTC = 0x01;
        PORTD = 0x01;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        //    zusätzliche Wartezeit für Löschen
        delay(4000);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
    
        //    Cursor Home                    0b 0000 001
        //    unerheblich                               0
        //    also                        0b 0000 0010
        //    muss übertragen werden
        
        //    zunächst das höherwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        //    Befehl schreiben
        //    also R/W = 0, RS = 0
        //    also PC6 = 0, PC7 = 0
        
        //    vereinfachte Schreibweise
        PORTC = 0x00;
        PORTD = 0x00;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    zunächst das niederwertige Nibbel an DB7 bis DB4
        //    also PC0 bis PC4
        
        //    vereinfachte Schreibweise
        PORTC = 0x02;
        PORTD = 0x02;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        //    zusätzliche Wartezeit für Löschen
        delay(4000);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause1);
        
        //
        //    Initialisierung ist damit abgeschlossen
        //
        
        //    kleinen Text ausgeben
        //    also Daten schreiben
        //    R/W = 0, RS = 1
        //    also PC6 = 0, PC7 = 1
        
        //    Buchstabe 'H' übertragen
        //    also 0b 0100 1000
    
        //    auch hier zuerst höherwertiges Nibbble übertragen,
        //    allerdings mit gesetztem PC7
        
        //    also zuerst 0b 1000 0100
        //    vereinfachte Schreibweise
        PORTC = 0x84;
        PORTD = 0x84;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann 0b 1000 1000
        //    vereinfachte Schreibweise
        PORTC = 0x88;
        PORTD = 0x88;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
    
        //    Buchstabe 'a' übertragen
        //    also 0b 0110 0001
    
        //    auch hier zuerst höherwertiges Nibbble übertragen,
        //    allerdings mit gesetztem PC7
        
        //    also zuerst 0b 1000 0110
        //    vereinfachte Schreibweise
        PORTC = 0x86;
        PORTD = 0x86;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann 0b 1000 0001
        //    vereinfachte Schreibweise
        PORTC = 0x81;
        PORTD = 0x81;
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung auf high legen
        //    also PC5
        PORTC |= (1 << PC5);
        PORTD |= (1 << PD5);
        //    Warten damit die Flanke sicher entsteht
        delay(100);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
        //    dann die Enableleitung wieder auf low legen
        //    also PC5
        PORTC &= ~(1 << PC5);
        PORTD &= ~(1 << PD5);
        //    Warten damit die Flanke sicher gefallen ist
        delay(200);
        
        //    Verzögerung zum Debuggen
        delay_ms(Pause2);
        
    
    
    
        //    Hintergrundbeleuchtung an
        PORTC = 0x10;
        PORTD = 0x10;
        
        while (1)
            {
            }
            return 0;
        
        
    }
    Wie Du siehst wird hier die komplette Initialisierung in der main() Funktion abgearbeitet. Wie im Kopf zu lesen ist, habe ich damals mein LCD an den Port C angeschlossen und zur Kontrolle acht LEDs an Port D angeschlossen. Wenn Du nun D verwendetest müsste das Programm sogar ohne Änderungen bei Dir laufen. Allerdings muss natürlich die Taktfrequenz richtig angegeben sein.

    Es ist übertrieben detailliert kommentiert, war mir damals bei der Fehlerbehebung eine große Hilfe.

    Nun hoffe ich, dass es auch Dir hilft.

    gutes Gelingen

    Uwe
    Legasteniker on Board!
    gefundene Rechtschreibfehler dienen der Belustigung des Lesers und dürfen von diesem behalten werden.

Seite 1 von 2 12 LetzteLetzte

Ähnliche Themen

  1. RN-Minicontrol mit RN-LCD-Adapter und DIP LCD-Display 4x20
    Von Neffez im Forum Schaltungen und Boards der Projektseite Mikrocontroller-Elektronik.de
    Antworten: 8
    Letzter Beitrag: 23.06.2008, 21:15
  2. LCD 4x20 mit KS0070B Chip kompatibel zum HD44780 Chip???
    Von Fighter-2 im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 3
    Letzter Beitrag: 09.11.2007, 16:06
  3. Fragen nach LCD Steuerung KS0070B
    Von denk im Forum Elektronik
    Antworten: 4
    Letzter Beitrag: 24.06.2007, 18:04
  4. 8*1 LCD Display mit Bascom?
    Von Powell im Forum Elektronik
    Antworten: 1
    Letzter Beitrag: 05.10.2006, 16:51
  5. Probleme mit KS0066U
    Von PhantomET im Forum Elektronik
    Antworten: 2
    Letzter Beitrag: 30.05.2005, 06:40

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

fchao-Sinus-Wechselrichter AliExpress