void hd44780_init(void) { /* init io pins */ CTRL_OUTPUT(); PIN_CLEAR(HD44780_RS); PIN_CLEAR(HD44780_EN); #ifdef HAVE_HD44780_RW PIN_CLEAR(HD44780_RW); #endif PIN_CLEAR(HD44780_D4); PIN_CLEAR(HD44780_D5); PIN_CLEAR(HD44780_D6); PIN_CLEAR(HD44780_D7); DATA_OUTPUT(); _delay_ms(40); PIN_SET(HD44780_D4); PIN_SET(HD44780_D5); clock_write(); _delay_ms(4); clock_write(); _delay_ms(1); clock_write(); /* init done */ _delay_ms(1); PIN_CLEAR(HD44780_D4); clock_write(); _delay_ms(1); /* configure for 4 bit, 2 lines, 5x9 font (datasheet, page 24) */ output_byte(0, CMD_FUNCTIONSET(0, 1, 0)); /* turn on display, cursor and blinking */ hd44780_config(0,0); /* clear display */ hd44780_clear(); /* set shift and increment */ output_byte(0, CMD_ENTRY_MODE(1, 0)); /* set ddram address */ output_byte(0, CMD_SETDRAMADR(0)); /* open file descriptor */ lcd = fdevopen(hd44780_put, NULL); /* set current virtual postion */ current_pos = 0; }
void hd44780_init(void) { /* verschiedene Hardware initialisieren */ hd44780_hw_init(); _delay_ms(40); #if HD44780_TYPE == HD44780_KS0066U /* Hardware initialisiert -> Standardprozedur KS0066U Datenblatt 4bit Mode */ output_nibble(0, 0x02); #else /* Hardware initialisiert -> Standardprozedur HD44780 Datenblatt 4bit Mode */ output_nibble(0, 0x03); _delay_ms(4); clock_write(); _delay_ms(1); clock_write(); _delay_ms(1); output_nibble(0, 0x02); //4bit mode _delay_ms(1); /* init done */ #endif /* configure for 4 bit, 2 lines, 5x9 font (datasheet, page 24) */ output_byte(0, CMD_FUNCTIONSET(0, 1, 0)); /* turn on display, cursor and blinking */ hd44780_config(0,0); /* clear display */ hd44780_clear(); /* set shift and increment */ output_byte(0, CMD_ENTRY_MODE(1, 0)); /* set ddram address */ output_byte(0, CMD_SETDRAMADR(0)); /* open file descriptor */ lcd = fdevopen(hd44780_put, NULL); /* set current virtual postion */ current_pos = 0; }
int hd44780_put(char d, FILE *stream) { uint8_t start = 0; #ifdef HD44780_MULTIENSUPPORT uint8_t en = 1; #endif if (d == '\n') { while (current_pos % LCD_CHAR_PER_LINE > 0) hd44780_put(' ', stream); if (current_pos >= LCD_MAX_CHAR) current_pos -= LCD_MAX_CHAR; return 0; } else if (d == '\r') { current_pos -= current_pos % LCD_CHAR_PER_LINE; return 0; } if (current_pos <= LCD_CHAR_PER_LINE - 1) { start = LCD_LINE_1_ADR - 0 + current_pos; #ifdef HD44780_MULTIENSUPPORT en = LCD_LINE_1_EN; #endif } else if (current_pos <= ( LCD_CHAR_PER_LINE * 2) - 1 ) { start = LCD_LINE_2_ADR - LCD_CHAR_PER_LINE + current_pos; #ifdef HD44780_MULTIENSUPPORT en = LCD_LINE_2_EN; #endif } else if (current_pos <= ( LCD_CHAR_PER_LINE * 3) - 1 ) { start = LCD_LINE_3_ADR - (LCD_CHAR_PER_LINE * 2) + current_pos; #ifdef HD44780_MULTIENSUPPORT en = LCD_LINE_3_EN; #endif } else if (current_pos <= ( LCD_CHAR_PER_LINE * 4) - 1 ) { start = LCD_LINE_4_ADR - (LCD_CHAR_PER_LINE * 3) + current_pos; #ifdef HD44780_MULTIENSUPPORT en = LCD_LINE_4_EN; #endif } #ifdef HD44780_MULTIENSUPPORT output_byte(0, CMD_SETDRAMADR(start), en); #else output_byte(0, CMD_SETDRAMADR(start), 1); #endif #ifdef DEBUG_HD44780 _delay_ms(50); #endif #ifdef HD44780_MULTIENSUPPORT output_byte(1, d, en); #else output_byte(1, d, 1); #endif current_pos++; if (current_pos == LCD_MAX_CHAR) current_pos = 0; return 0; }
int hd44780_put(char d, FILE *stream) { uint8_t start = 0; if (d == '\n') { while (current_pos % 20 > 0) hd44780_put(' ', stream); if (current_pos >= 80) current_pos -= 80; return 0; } else if (d == '\r') { current_pos -= current_pos % 20; return 0; } #if HD44780_TYPE == HD44780_ORIGINAL if (current_pos <= 19) start = 0x00 - 00 + current_pos; else if (current_pos <= 39) start = 0x20 - 20 + current_pos; else if (current_pos <= 59) start = 0x40 - 40 + current_pos; else if (current_pos <= 79) start = 0x60 - 60 + current_pos; #elif HD44780_TYPE == HD44780_DISPTECH if (current_pos <= 19) start = 0x00 - 0 + current_pos; else if (current_pos <= 39) start = 0x40 - 20 + current_pos; else if (current_pos <= 59) start = 0x10 - 40 + current_pos; else if (current_pos <= 79) start = 0x50 - 60 + current_pos; #elif HD44780_TYPE == HD44780_KS0067B if (current_pos <= 19) start = 0x00 - 0 + current_pos; else if (current_pos <= 39) start = 0x40 - 20 + current_pos; else if (current_pos <= 59) start = 0x14 - 40 + current_pos; else if (current_pos <= 79) start = 0x54 - 60 + current_pos; #elif HD44780_TYPE == HD44780_KS0066U if (current_pos <= 19) start = 0x00 - 0 + current_pos; else if (current_pos <= 39) start = 0x40 - 20 + current_pos; else if (current_pos <= 59) start = 0x10 - 40 + current_pos; else if (current_pos <= 79) start = 0x50 - 60 + current_pos; #else #error "unknown hd44780 compatible controller type!" #endif output_byte(0, CMD_SETDRAMADR(start)); #ifdef DEBUG_HD44780 _delay_ms(50); #endif output_byte(1, d); current_pos++; if (current_pos == 80) current_pos = 0; return 0; }
void hd44780_init(void) { /* verschiedene Hardware initialisieren */ hd44780_hw_init(); _delay_ms(40); #if CONF_HD44780_TYPE == HD44780_KS0066U /* Hardware initialisiert -> Standardprozedur KS0066U Datenblatt 4bit Mode */ output_nibble(0, 0x02, 1); #else /* Hardware initialisiert -> Standardprozedur HD44780 Datenblatt 4bit Mode */ output_nibble(0, 0x03,1); _delay_ms(4); #ifdef HD44780_2WIRE output_nibble(0, 0x03,1); #else clock_write(1); #endif /*HD44780_2WIRE*/ _delay_ms(1); #ifdef HD44780_2WIRE output_nibble(0, 0x03,1); #else clock_write(1); #endif /*HD44780_2WIRE*/ _delay_ms(1); output_nibble(0, 0x02,1); //4bit mode _delay_ms(1); /* init done */ #endif /*CONF_HD44780_TYPE*/ /* configure for 4 bit, 2 lines, 5x8 font (datasheet, page 24) */ output_byte(0, CMD_FUNCTIONSET(0, 1, 0), 1); /* turn on display, cursor and blinking */ hd44780_config(0,0,1); /* clear display */ hd44780_clear(1); /* set shift and increment */ output_byte(0, CMD_ENTRY_MODE(1, 0),1); /* set ddram address */ output_byte(0, CMD_SETDRAMADR(0),1); /*Configure Controller 2 */ #ifdef HD44780_MULTIENSUPPORT /* verschiedene Hardware initialisieren */ hd44780_hw_init(); _delay_ms(40); #if CONF_HD44780_TYPE == HD44780_KS0066U /* Hardware initialisiert -> Standardprozedur KS0066U Datenblatt 4bit Mode */ output_nibble(0, 0x02, 2); #else /* Hardware initialisiert -> Standardprozedur HD44780 Datenblatt 4bit Mode */ output_nibble(0, 0x03,2); _delay_ms(4); clock_write(2); _delay_ms(1); clock_write(2); _delay_ms(1); output_nibble(0, 0x02,2); //4bit mode _delay_ms(1); /* init done */ #endif /* configure for 4 bit, 2 lines, 5x9 font (datasheet, page 24) */ output_byte(0, CMD_FUNCTIONSET(0, 1, 0), 2); /* turn on display, cursor and blinking */ hd44780_config(0,0,2); /* clear display */ hd44780_clear(2); /* set shift and increment */ output_byte(0, CMD_ENTRY_MODE(1, 0),2); /* set ddram address */ output_byte(0, CMD_SETDRAMADR(0),2); #endif /* set current virtual postion */ current_pos = 0; }