-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcd.c
More file actions
116 lines (102 loc) · 1.57 KB
/
lcd.c
File metadata and controls
116 lines (102 loc) · 1.57 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "avr.h"
#include "lcd.h"
#define RS_PIN 0
#define RW_PIN 1
#define EN_PIN 2
void set_data(unsigned char x)
{
PORTD = x;
DDRD = 0xff;
}
static unsigned char get_data(void)
{
DDRD = 0x00;
return PIND;
}
static inline void sleep_700ns(void)
{
NOP();
NOP();
NOP();
}
static unsigned char input(unsigned char rs)
{
unsigned char d;
if (rs) {
SET_BIT(PORTB, RS_PIN);
}
else {
CLR_BIT(PORTB, RS_PIN);
}
SET_BIT(PORTB, RW_PIN);
get_data(); // Note: Return value ignored here
SET_BIT(PORTB, EN_PIN);
// avr_wait(7);
d = get_data();
CLR_BIT(PORTB, EN_PIN);
return d;
}
static void output(unsigned char d, unsigned char rs)
{
if (rs) {
SET_BIT(PORTB, RS_PIN);
}
else {
CLR_BIT(PORTB, RS_PIN);
}
CLR_BIT(PORTB, RW_PIN);
set_data(d);
SET_BIT(PORTB, EN_PIN);
// avr_wait(7);
CLR_BIT(PORTB, EN_PIN);
}
void write(unsigned char c, unsigned char rs)
{
while (input(0) & 0x80); // Module Busy check
output(c, rs);
}
void lcd_init(void)
{
SET_BIT(DDRB, RS_PIN);
SET_BIT(DDRB, RW_PIN);
SET_BIT(DDRB, EN_PIN);
avr_wait(16);
output(0x30, 0);
avr_wait(5);
output(0x30, 0);
avr_wait(1);
write(0x3c, 0);
write(0x0c, 0);
write(0x06, 0);
write(0x01, 0);
}
void lcd_clr(void)
{
write(0x01, 0);
}
void lcd_pos(unsigned char r, unsigned char c)
{
unsigned char n = r * 40 + c;
write(0x02, 0);
while (n--) {
write(0x14, 0);
}
}
void lcd_put(char c)
{
write(c, 1);
}
void lcd_puts1(const char *s)
{
char c;
while ((c = pgm_read_byte(s++)) != 0) {
write(c, 1);
}
}
void lcd_puts2(const char *s)
{
char c;
while ((c = *(s++)) != 0) {
write(c, 1);
}
}