-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtty.hh
More file actions
80 lines (68 loc) · 1.75 KB
/
tty.hh
File metadata and controls
80 lines (68 loc) · 1.75 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
// (C) 2026 Lumisetiq
#ifndef TTY_HH
#define TTY_HH
class TTY {
private:
const uint8_t RS = 15, E = 14, D4 = 13, D5 = 12, D6 = 11, D7 = 10;
void pulseEnable() {
digitalWrite(E, LOW); delayMicroseconds(1);
digitalWrite(E, HIGH); delayMicroseconds(1);
digitalWrite(E, LOW); delayMicroseconds(40);
}
void write4Bits(uint8_t value) {
digitalWrite(D4, (value >> 0) & 0x01);
digitalWrite(D5, (value >> 1) & 0x01);
digitalWrite(D6, (value >> 2) & 0x01);
digitalWrite(D7, (value >> 3) & 0x01);
pulseEnable();
}
void send(uint8_t value, uint8_t mode) {
digitalWrite(RS, mode);
write4Bits(value >> 4);
write4Bits(value);
}
public:
void init() {
pinMode(RS, OUTPUT); pinMode(E, OUTPUT);
pinMode(D4, OUTPUT); pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT); pinMode(D7, OUTPUT);
delay(50);
write4Bits(0x03); delay(5);
write4Bits(0x03); delay(5);
write4Bits(0x03); delay(1);
write4Bits(0x02);
send(0x28, 0); send(0x0C, 0); send(0x06, 0);
clearText();
}
void clearText() {
send(0x01, 0);
delay(2);
refreshStaticElements();
}
void refreshStaticElements() {
uint8_t row0 = 0x80;
send(row0, 0);
for(int i=0; i<4; i++) send(i, 1);
uint8_t row1 = 0xC0;
send(row1, 0);
for(int i=4; i<8; i++) send(i, 1);
}
void setCursor(uint8_t col, uint8_t row) {
uint8_t x = col + 4;
uint8_t addr = (row == 0) ? (0x80 + x) : (0xC0 + x);
send(addr, 0);
}
void print(const char* str) {
while(*str) send(*str++, 1);
}
void writeFrame(uint8_t frame[8][8]) {
for (uint8_t i = 0; i < 8; i++) {
send(0x40 + (i * 8), 0);
for (uint8_t j = 0; j < 8; j++) {
send(frame[i][j], 1);
}
}
refreshStaticElements();
}
};
#endif