-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD_Interface.cpp
More file actions
95 lines (78 loc) · 1.64 KB
/
LCD_Interface.cpp
File metadata and controls
95 lines (78 loc) · 1.64 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
#include "LCD_Interface.h"
LCD_Interface::LCD_Interface()
{
}
void LCD_Interface::set8bitDataPins(uint8_t data)
{
for (int i = 0; i < 8; i++)
{
digitalWrite(this->_dataPins[i], (data >> i) & 0x01);
}
}
void LCD_Interface::set4bitDataPins(uint8_t data)
{
for (int i = 4; i < 8; i++)
{
digitalWrite(this->_dataPins[i], (data >> (i - 4)) & 0x01);
}
}
void LCD_Interface::setCommandMode()
{
digitalWrite(this->_RS, LOW); // Set command mode
}
void LCD_Interface::setDataMode()
{
digitalWrite(this->_RS, HIGH);
}
void LCD_Interface::setWriteMode()
{
digitalWrite(this->_RW, LOW); // Set write mode
}
void LCD_Interface::setReadMode()
{
digitalWrite(this->_RW, HIGH); // Set read mode
}
void LCD_Interface::dataLatch()
{
if (this->_isTop)
{
digitalWrite(this->_enable, HIGH);
delay(1);
digitalWrite(this->_enable, LOW);
}
else
{
digitalWrite(this->_enable2, HIGH);
delay(1);
digitalWrite(this->_enable2, LOW);
}
}
// For 8-bit parallel
uint8_t LCD_Interface::readBusyFlagAC()
{
setCommandMode();
setReadMode();
digitalWrite(this->_enable, HIGH);
delay(1);
digitalWrite(this->_enable, LOW);
// Read data
uint8_t rxData;
int pos = 7;
for (int i = 0; i < 8; i++)
{
rxData |= (digitalRead(_dataPins[i]) << pos);
Serial.print(digitalRead(_dataPins[i]));
pos--;
}
Serial.print(" RBF:");
Serial.println(rxData);
return rxData;
}
void LCD_Interface::setTop()
{
this->_isTop = true;
}
void LCD_Interface::setBottom()
{
this->_isTop = this->_is4x40 ? false : true;
}