blob: 927b90fa46ea753e84ce72122b67bbdf79bb9982 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "lcd.h"
#include <avr/io.h>
#include <util/delay.h>
#define B_SRCLK PB0
#define B_LCDE PB3
#define B_SRD_LCDRS PB4
static void lcd_pin(bool value)
{
/* cheat, put the clock in front.
* result:
* clk, d0 | clk, d1 | clk... d7 | clk, rs.
* ^- first clk ignored ^- last clk from setting R/S
*/
PORTB |= (1 << B_SRCLK);
PORTB &= ~(1 << B_SRCLK);
if (value)
PORTB |= (1 << B_SRD_LCDRS);
else
PORTB &= ~(1 << B_SRD_LCDRS);
}
void lcd_command(uint8_t cmd, bool isdata)
{
uint8_t i;
for (i = 1; i; i <<= 2)
lcd_pin(cmd & i);
for (i = 1 << 7; i; i >>= 2)
lcd_pin(cmd & i);
lcd_pin(isdata);
__asm__ ("nop\n");
PORTB |= (1 << B_LCDE);
__asm__ ("nop\n");
PORTB &= ~(1 << B_LCDE);
__asm__ ("nop\n");
if (!isdata)
_delay_us(50);
}
void lcd_puts(const char * PROGMEM ptr, uint8_t cnt)
{
while (cnt--) {
uint8_t ch = __LPM(ptr++);
lcd_put(ch);
}
}
const char PROGMEM boot[] = "boot";
void lcd_init(void)
{
PORTB &= ~((1 << B_SRCLK) | (1 << B_LCDE) | (1 << B_SRD_LCDRS));
DDRB |= (1 << B_SRCLK) | (1 << B_LCDE) | (1 << B_SRD_LCDRS);
_delay_ms(15);
lcd_command(0x38, 0);
lcd_command(0x0c, 0);
lcd_command(0x06, 0);
lcd_command(0x02, 0);
_delay_ms(2);
lcd_line1();
lcd_puts(boot, sizeof(boot) - 1);
}
|