LCD-Display HD44780 kompatibles Display In verschiedenen Ausführungen erhältlich Sehr gute Dokumentation unter http://www.mikrocontroller.net/articles/HD44780 Verwendung der Bibliothek von Peter Fleury Anpassungen in lcd.h vornehmen Pinbelegung Taktfrequenz, hier XTAL Anpassungen im Makefile vornehmen Schönes Tutorial für einfache Routinen unter http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung
Pinbelegung
Schaltung zum Anschluss des LCD-Displays im 4 Bit-Mode
Funktionen aus lcd.h/lcd.c void lcd_init(uint8_t dispAttr); LCD_DISP_OFF LCD_DISP_ON LCD_DISP_ON_CURSOR LCD_DISP_ON_CURSOR_BLINK void lcd_clrscr(void); void lcd_gotoxy(uint8_t x, uint8_t y); void lcd_putc(char c); void lcd_puts(const char *s);
Funktionen aus lcd.h/lcd.c void lcd_puts_p(const char *progmem_s); void lcd_command(uint8_t cmd); void lcd_data(uint8_t data); Hinweis: In lcd.c ist das Macro _BV häufig verwendet. Es ist in <avr/sfr_defs.h> definiert. #define _BV( bit ) ( 1<<(bit) )
Die wichtigsten Anpassungen in lcd.h #define XTAL F_CPU /* Takt aus Makefile!! */ #define LCD_PORT PORTC /**< 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 PORTD /**< port for RS line */ #define LCD_RS_PIN 5 /**< pin for RS line */ #define LCD_RW_PORT PORTD /**< port for RW line */ #define LCD_RW_PIN 6 /**< pin for RW line */ #define LCD_E_PORT PORTD /**< port for Enable line */ #define LCD_E_PIN 7 /**< pin for Enable line */
Benutzerdefinierte Zeichen http://www. mugui. de/bin/menu. php Bis zu 8 benutzerdefinierte Zeichen (5x8 pix) oder zu 4 (5X10 pix) können im Character Generator RAM (CGRAM) abgelegt werden. Sie werden mit P. Fleury dargestellt, in dem man lcd_putc(0..8) aufruft. Die Zeichen werden über lcd_command (senden der Adresse) und lcd_data an das Display übertragen und stehen dann zur Verfügung.
Definition © (zusammengestzt aus 2 Zeichen) static const unsigned char copyRightChar[] PROGMEM= { 0x07, 0x08, 0x13, 0x14, 0x14, 0x13, 0x08, 0x07, 0x00, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00 };
Übertragen / Anzeigen von © lcd_puts("Copyright: "); /* * load two userdefined characters from program memory * into LCD controller CG RAM location 0 and 1 */ /* set CG RAM start address 0 */ lcd_command(_BV(LCD_CGRAM)); for(i=0; i<16; i++) { lcd_data(pgm_read_byte_near(©RightChar[i])); } BV(LCD_CGRAM) entspricht 1<<LCD_CGRAM
HD44780 Befehlssatz Die LCD-Kommandos sind in lcd.h detailliert ausgeführt
Kodierung der Steuerbits
2/4 -zeiliges 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 0x20 /**< 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 */
Alternative LCD-Bibliothek http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung