2 ATMega pinout (with LCD_SHIFTREG):
8 ATMega pinout (without LCD_SHIFTREG):
20 In both cases, HD44780 R/W needs to be connected to ground.
28 #define CLOCK_PORT PORTB
29 #define CLOCK_BIT 0x02
30 #define REGSEL_PORT PORTB
31 #define REGSEL_BIT 0x01
33 #define CLOCK_PORT PORTD
34 #define CLOCK_BIT 0x20
35 #define REGSEL_PORT PORTD
36 #define REGSEL_BIT 0x10
40 #define LCD_BUFSIZE 32
43 #define NOP() __asm__("nop")
46 static volatile uint8_t lcd_busy = 0;
47 static uint8_t lcd_buffer[LCD_BUFSIZE];
48 static volatile uint8_t lcd_buf_head = 0;
49 static volatile uint8_t lcd_buf_tail = 0;
52 static void lcd_clock(void)
55 CLOCK_PORT |= CLOCK_BIT;
57 CLOCK_PORT &= ~CLOCK_BIT;
60 static void lcd_set_data(uint8_t d)
66 PORTB = (PORTB&~0x04)|((d&1)<<2);
73 PORTD = (PORTD&0x3F) | (d<<6);
74 PORTB = (PORTB&0xC0) | (d>>2);
78 static void lcd_command(uint8_t c)
80 REGSEL_PORT &= ~REGSEL_BIT;
85 static void lcd_delay(uint16_t us)
89 timer_start_us(0, us);
96 static void lcd_wait(void)
101 static void lcd_buffer_push(uint8_t byte)
103 while((lcd_buf_head+1)%sizeof(lcd_buffer)==lcd_buf_tail) ;
104 lcd_buffer[lcd_buf_head] = byte;
105 lcd_buf_head = (lcd_buf_head+1)%sizeof(lcd_buffer);
108 static uint8_t lcd_buffer_pop(void)
110 uint8_t byte = lcd_buffer[lcd_buf_tail];
111 lcd_buf_tail = (lcd_buf_tail+1)%sizeof(lcd_buffer);
115 static void lcd_timer(void)
119 if(lcd_buf_head!=lcd_buf_tail)
121 uint8_t byte = lcd_buffer_pop();
124 REGSEL_PORT |= REGSEL_BIT;
125 byte = lcd_buffer_pop();
128 REGSEL_PORT &= ~REGSEL_BIT;
130 REGSEL_PORT |= REGSEL_BIT;
143 TIMER_SET_CALLBACK(0, lcd_timer)
174 void lcd_gotoxy(uint8_t x, uint8_t y)
183 lcd_buffer_push(a|0x80);
192 void lcd_write(uint8_t c)
198 lcd_buffer_push(0xFF);
204 REGSEL_PORT |= REGSEL_BIT;