-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lcd.cpp
148 lines (122 loc) · 2.37 KB
/
Lcd.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "Lcd.h"
Lcd::Lcd(void) {
line = 0;
max_line = 6;
pinMode(PIN_SCE, OUTPUT);
pinMode(PIN_RESET, OUTPUT);
pinMode(PIN_DC, OUTPUT);
pinMode(PIN_SDIN, OUTPUT);
pinMode(PIN_SCLK, OUTPUT);
digitalWrite(PIN_RESET, LOW);
digitalWrite(PIN_RESET, HIGH);
write(LCD_C, 0x21 ); // LCD Extended Commands.
write(LCD_C, 0xBf ); // Set LCD Vop (Contrast).
write(LCD_C, 0x04 ); // Set Temp coefficent. //0x04
write(LCD_C, 0x14 ); // LCD bias mode 1:48. //0x13
write(LCD_C, 0x0C ); // LCD in normal mode.
write(LCD_C, 0x20 );
write(LCD_C, 0x0C );
}
void Lcd::gotoXY(int x, int y)
{
write( 0, 0x80 | x); // Column.
write( 0, 0x40 | y); // Row.
}
void Lcd::drawBox(void)
{
int j;
for(j = 0; j < 84; j++) // top
{
gotoXY(j, 0);
write(LCD_D, 0x01);
}
for(j = 0; j < 84; j++) //Bottom
{
gotoXY(j, 5);
write(LCD_D, 0x80);
}
for(j = 0; j < 6; j++) // Right
{
gotoXY(83, j);
write(LCD_D, 0xff);
}
for(j = 0; j < 6; j++) // Left
{
gotoXY(0, j);
write(LCD_D, 0xff);
}
}
void Lcd::scroll(String message)
{
int scrollPosition = -10;
for (int i = scrollPosition; i < scrollPosition + 11; i++)
{
if ((i >= message.length()) || (i < 0))
{
character(' ');
}
else
{
character(message.charAt(i));
}
}
scrollPosition++;
if ((scrollPosition >= message.length()) && (scrollPosition > 0))
{
scrollPosition = -10;
}
}
void Lcd::print(char *characters)
{
while (*characters)
{
character(*characters++);
}
}
void Lcd::println(char *characters)
{
print(characters);
newline();
}
void Lcd::print(int characters) {
char value[10];
itoa (characters, value, 10);
print(value);
}
void Lcd::println(int characters) {
print(characters);
newline();
}
void Lcd::newline() {
if(line >= max_line) {
line = 0;
}else{
line++;
}
gotoXY(0,line);
}
void Lcd::write(byte dc, byte data)
{
digitalWrite(PIN_DC, dc);
digitalWrite(PIN_SCE, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_SCE, HIGH);
}
void Lcd::character(char character)
{
write(LCD_D, 0x00);
for (int index = 0; index < 5; index++)
{
write(LCD_D, ASCII[character - 0x20][index]);
}
write(LCD_D, 0x00);
}
void Lcd::clear(void)
{
for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
{
write(LCD_D, 0x00);
}
gotoXY(0,0);
line = 0;
}