Spurius
01.05.2006, 12:58
Hallo,
ich versuche gerade eine eigene LCD-Ansteuerung ohne Lib hinzukriegen, leider wird auf dem Display nicht angezeigt...
#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>
#define LCD_RS_PORT PORTB
#define LCD_RS_PIN 3
#define LCD_DATA0_PORT PORTD /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT PORTD /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT PORTD /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT PORTB /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN 5 /**< pin for 4bit data bit 0 */
#define LCD_DATA1_PIN 6 /**< pin for 4bit data bit 1 */
#define LCD_DATA2_PIN 7 /**< pin for 4bit data bit 2 */
#define LCD_DATA3_PIN 0
#define LCD_RW_PORT PORTB /**< port for RW line */
#define LCD_RW_PIN 4 /**< pin for RW line */
#define LCD_E_PORT PORTB /**< port for Enable line */
#define LCD_E_PIN 2 /**< pin for Enable line */
#define LCD_E_PORT PORTB /**< port for Enable line */
#define LCD_E_PIN 1 /**< pin for Enable line */
void write_data(uint8_t wert)
{
if(wert & (1<<0))
{
LCD_DATA0_PORT &= ~(1 << LCD_DATA0_PIN);
}
else
{
LCD_DATA0_PORT |= (1 << LCD_DATA0_PIN);
}
if(wert & (1<<1))
{
LCD_DATA1_PORT &= ~(1 << LCD_DATA1_PIN);
}
else
{
LCD_DATA1_PORT |= (1 << LCD_DATA1_PIN);
}
if(wert & (1<<2))
{
LCD_DATA2_PORT &= ~(1 << LCD_DATA2_PIN);
}
else
{
LCD_DATA2_PORT |= (1 << LCD_DATA2_PIN);
}
if(wert & (1<<3))
{
LCD_DATA3_PORT &= ~(1 << LCD_DATA3_PIN);
}
else
{
LCD_DATA3_PORT |= (1 << LCD_DATA3_PIN);
}
}
void init_lcd(void)
{
_delay_ms(20);
LCD_RS_PORT &= ~(1<<LCD_RS_PIN); /* Steuerregister wird angesprochen */
_delay_ms(8);
write_data(0x3);
_delay_ms(1);
write_data(0x3);
LCD_RW_PORT |= (1<<LCD_RW_PIN); /*Lesezugriff, warten bis RW 0 */
DDRB = 0xfe; /*PB0 als Eingang, um Busyflag einzulesen*/
while(LCD_DATA3_PORT & (1<<LCD_DATA3_PIN));
LCD_RW_PORT &= ~(1<<LCD_RW_PIN);
DDRB = 0xff;
write_data(0x2);
LCD_RW_PORT |= ~(1<<LCD_RW_PIN);
DDRB = 0xfe;
while(LCD_DATA3_PORT & (1<<LCD_DATA3_PIN));
LCD_RW_PORT &= (1<<LCD_RW_PIN);
DDRB = 0xff;
write_data(0x2); /*System-Set oberes Nibble */
write_data(0x8); /*System-Set unteres Nibble */
write_data(0x0); /*Display on/off, Display on, Unterstrich Cursor on, blinkender Cursor on*/
write_data(0xF);
write_data(0x0); /* Cursor Home */
write_data(0x2);
LCD_RS_PORT |= (1<<LCD_RS_PIN); /*Datenregister auswählen*/
write_data(0x19);
}
void main(void)
{
DDRB = 0xFF;
DDRD = 0xFF;
init_lcd();
for(;;);
}
Ich habe versucht nach der Anleitung im PDF zu gehen, aber irgendwie habe ich nie Enable verwendet..
Gruß
Martin
ich versuche gerade eine eigene LCD-Ansteuerung ohne Lib hinzukriegen, leider wird auf dem Display nicht angezeigt...
#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>
#define LCD_RS_PORT PORTB
#define LCD_RS_PIN 3
#define LCD_DATA0_PORT PORTD /**< port for 4bit data bit 0 */
#define LCD_DATA1_PORT PORTD /**< port for 4bit data bit 1 */
#define LCD_DATA2_PORT PORTD /**< port for 4bit data bit 2 */
#define LCD_DATA3_PORT PORTB /**< port for 4bit data bit 3 */
#define LCD_DATA0_PIN 5 /**< pin for 4bit data bit 0 */
#define LCD_DATA1_PIN 6 /**< pin for 4bit data bit 1 */
#define LCD_DATA2_PIN 7 /**< pin for 4bit data bit 2 */
#define LCD_DATA3_PIN 0
#define LCD_RW_PORT PORTB /**< port for RW line */
#define LCD_RW_PIN 4 /**< pin for RW line */
#define LCD_E_PORT PORTB /**< port for Enable line */
#define LCD_E_PIN 2 /**< pin for Enable line */
#define LCD_E_PORT PORTB /**< port for Enable line */
#define LCD_E_PIN 1 /**< pin for Enable line */
void write_data(uint8_t wert)
{
if(wert & (1<<0))
{
LCD_DATA0_PORT &= ~(1 << LCD_DATA0_PIN);
}
else
{
LCD_DATA0_PORT |= (1 << LCD_DATA0_PIN);
}
if(wert & (1<<1))
{
LCD_DATA1_PORT &= ~(1 << LCD_DATA1_PIN);
}
else
{
LCD_DATA1_PORT |= (1 << LCD_DATA1_PIN);
}
if(wert & (1<<2))
{
LCD_DATA2_PORT &= ~(1 << LCD_DATA2_PIN);
}
else
{
LCD_DATA2_PORT |= (1 << LCD_DATA2_PIN);
}
if(wert & (1<<3))
{
LCD_DATA3_PORT &= ~(1 << LCD_DATA3_PIN);
}
else
{
LCD_DATA3_PORT |= (1 << LCD_DATA3_PIN);
}
}
void init_lcd(void)
{
_delay_ms(20);
LCD_RS_PORT &= ~(1<<LCD_RS_PIN); /* Steuerregister wird angesprochen */
_delay_ms(8);
write_data(0x3);
_delay_ms(1);
write_data(0x3);
LCD_RW_PORT |= (1<<LCD_RW_PIN); /*Lesezugriff, warten bis RW 0 */
DDRB = 0xfe; /*PB0 als Eingang, um Busyflag einzulesen*/
while(LCD_DATA3_PORT & (1<<LCD_DATA3_PIN));
LCD_RW_PORT &= ~(1<<LCD_RW_PIN);
DDRB = 0xff;
write_data(0x2);
LCD_RW_PORT |= ~(1<<LCD_RW_PIN);
DDRB = 0xfe;
while(LCD_DATA3_PORT & (1<<LCD_DATA3_PIN));
LCD_RW_PORT &= (1<<LCD_RW_PIN);
DDRB = 0xff;
write_data(0x2); /*System-Set oberes Nibble */
write_data(0x8); /*System-Set unteres Nibble */
write_data(0x0); /*Display on/off, Display on, Unterstrich Cursor on, blinkender Cursor on*/
write_data(0xF);
write_data(0x0); /* Cursor Home */
write_data(0x2);
LCD_RS_PORT |= (1<<LCD_RS_PIN); /*Datenregister auswählen*/
write_data(0x19);
}
void main(void)
{
DDRB = 0xFF;
DDRD = 0xFF;
init_lcd();
for(;;);
}
Ich habe versucht nach der Anleitung im PDF zu gehen, aber irgendwie habe ich nie Enable verwendet..
Gruß
Martin