Sorry, stimmt das ich nicht alles gepostet habe.
Hier ist meine gesamte c-Datei:
und die h-Datei:Code:#include "HD44780.h" void LCD_Ctrl (unsigned char data) { PORTB &= ~(1<<RS); //erstes Nibble PORTC = ((data & 0xF0)>>4); PORTB |= (1<<EN); asm volatile ("nop"); PORTB &= ~(1<<EN); //zweites Nibble PORTC = data & 0x0F; PORTB |= (1<<EN); asm volatile ("nop"); PORTB &= ~(1<<EN); _delay_us(100); } void LCD_Home (void) { //Display löschen und auf Homeposition setzen LCD_Ctrl (0x01); _delay_ms(1); LCD_Ctrl (0x02); _delay_ms(5); } void LCD_Data (unsigned char data) { _delay_us(100); //erstes Nibble PORTC = ((data & 0xF0)>>4); PORTB |= (1<<RS); PORTB |= (1<<EN); asm volatile ("nop"); PORTB &= ~(1<<EN); //zweites Nibble PORTC = data & 0x0F; PORTB |= (1<<RS); PORTB |= (1<<EN); asm volatile ("nop"); PORTB &= ~(1<<EN); PORTB &= ~(1<<RS); _delay_us(100); } void LCD_Init(void) { DDRC |= 0x0F; //PC0 - PC3 als Ausgang DDRB |= (1<<PB6) | (1<<PB7); //RS und EN als Ausgang _delay_ms(15); LCD_Ctrl (0x28); _delay_ms(5); LCD_Ctrl (0x28); _delay_ms(1); LCD_Ctrl (0x28); /* 0b00001DCB 0 1 D: Display aus ein C: Cursor aus ein B: Blinken aus ein 0x0F: Display ein, Cursor sichtbar, Blinken ein 0x0E: Display ein, Cursor sichtbar, Blinken aus 0x0C: Display ein, Cursor unsichtbar, Blinken aus */ _delay_ms(1); LCD_Ctrl (0x0C); _delay_ms(1); LCD_Ctrl (0x01); _delay_ms(1); LCD_Ctrl (0x02); _delay_ms(5); } void LCD_Pos (unsigned int zeile, unsigned int spalte) { LCD_Ctrl (0x80 + spalte - 1+ 0x40 * (zeile - 1)); _delay_us (100); } void LCD_String (char text [20]) { unsigned int i=0; while ((!(text[i] == 0)) & (i < 20)) { LCD_Data (text[i]); i++; } } void LCD_Integer (unsigned int data) { unsigned char a; a = (data % 10000)/1000; //Tausender LCD_Data (a + 48); a = (data % 1000)/100; //Hunderter LCD_Data (a + 48); a = (data % 100)/10; //Zehner LCD_Data (a + 48); a = data % 10; //Einer LCD_Data (a + 48); }
Hier findest du etwas über LCDs http://www.pacificdisplay.com/lcd_mod_if.htmCode:#include <avr/io.h> #include <stdio.h> #include <stdlib.h> #include <util/delay.h> #define RS PB7 #define EN PB6
Schau dir einmal die erste PDF an (How to use a Character Display Module - Part 1), dort steht wie du die mit Tasten ansteuern kannst. Zum Testen ist es so optimal. So kannst du Programmfehler ausschließen.
PS: Ich habe ein HD44780-Display angesteuert (ein 2x16). Dieser sollte aber mit dem KS0073 kompatibel sein bzw mit leichten Änderungen anzusteuern sein.
MfG Hannes







Zitieren

Lesezeichen