26 #include <avr/pgmspace.h> 27 #include "avr_helper.h" 33 #define D_D_R(x) (*(&x - 1)) 34 #if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) 36 #define P_I_N(x) ( &PORTF==&(x) ? _SFR_IO8(0x00) : (*(&x - 2)) ) 38 #define P_I_N(x) (*(&x - 2)) 43 #define lcd_e_delay() __asm__ __volatile__( "rjmp 1f\n 1:" ); 44 #define lcd_e_high() LCD_E_PORT |= _BV(LCD_E_PIN); 45 #define lcd_e_low() LCD_E_PORT &= ~_BV(LCD_E_PIN); 46 #define lcd_e_toggle() toggle_e() 47 #define lcd_rw_high() LCD_RW_PORT |= _BV(LCD_RW_PIN) 48 #define lcd_rw_low() LCD_RW_PORT &= ~_BV(LCD_RW_PIN) 49 #define lcd_rs_high() LCD_RS_PORT |= _BV(LCD_RS_PIN) 50 #define lcd_rs_low() LCD_RS_PORT &= ~_BV(LCD_RS_PIN) 55 #define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_1LINE 57 #define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES 61 #define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_1LINE 63 #define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_2LINES 67 #if LCD_CONTROLLER_KS0073 70 #define KS0073_EXTENDED_FUNCTION_REGISTER_ON 0x24 71 #define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x20 72 #define KS0073_4LINES_MODE 0x09 81 static void toggle_e(
void);
93 static inline void _delayFourCycles(
unsigned int __count)
96 __asm__ __volatile__(
"rjmp 1f\n 1:" );
98 __asm__ __volatile__ (
111 #define delay(us) _delayFourCycles( ( ( 1*(XTAL/4000) )*us)/1000 ) 116 static void toggle_e(
void)
133 static void lcd_write(uint8_t data,uint8_t rs)
135 unsigned char dataBits ;
201 #define lcd_write(d,rs) if (rs) *(volatile uint8_t*)(LCD_IO_DATA) = d; else *(volatile uint8_t*)(LCD_IO_FUNCTION) = d; 215 uint8_t lcd_read(uint8_t rs)
275 #define lcd_read(rs) (rs) ? *(volatile uint8_t*)(LCD_IO_DATA+LCD_IO_READ) : *(volatile uint8_t*)(LCD_IO_FUNCTION+LCD_IO_READ) 284 static uint8_t lcd_waitbusy(
void)
290 while ( (c=lcd_read(0)) & (1<<LCD_BUSY)) {}
296 return (lcd_read(0));
305 static inline void lcd_newline(uint8_t pos)
307 register uint8_t addressCounter;
320 #if KS0073_4LINES_MODE 407 uint8_t lcd_getxy(
void)
409 return lcd_waitbusy();
441 pos = lcd_waitbusy();
448 #if LCD_WRAP_LINES==1 488 while ( (c = *s++) ) {
505 while ( (c = pgm_read_byte(progmem_s++)) ) {
584 MCUCR = _BV(SRE) | _BV(SRW);
588 lcd_write(LCD_FUNCTION_8BIT_1LINE,0);
590 lcd_write(LCD_FUNCTION_8BIT_1LINE,0);
592 lcd_write(LCD_FUNCTION_8BIT_1LINE,0);
596 #if KS0073_4LINES_MODE 600 lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF);
void lcd_puts_p(const char *progmem_s)
Display string from program memory without auto linefeed.
void lcd_gotoxy(uint8_t x, uint8_t y)
Set cursor to specified position.
void lcd_clrscr(void)
Clear display and set cursor to home position.
void lcd_home(void)
Set cursor to home position.
void lcd_command(uint8_t cmd)
Send LCD controller instruction command.
void lcd_data(uint8_t data)
Send data byte to LCD controller.
void lcd_puts(const char *s)
Display string without auto linefeed.
void lcd_init(void)
Initialize display and select type of cursor.
void lcd_putc(char c)
Display character at current cursor position.