forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 673
/
LCD_5110.cpp
166 lines (146 loc) · 4.64 KB
/
LCD_5110.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// LCD_5110.cpp
// Library C++ code
// ----------------------------------
// Developed with embedXcode
//
// Project LCD 5110
// Created by Rei VILO on 28/05/12
// Copyright (c) 2012 http://embeddedcomputing.weebly.com
// Licence CC = BY SA NC
//
#include "LCD_5110.h"
const uint8_t _commandLCD = 0x00;
const uint8_t _dataLCD = 0x01;
// 2015-02-07 Rei Vilo
// Pins numbers instead of pins names
LCD_5110::LCD_5110() { // pins names in MSP430G2553
LCD_5110(10, // P2_2 Chip Select
12, // P2_4 Serial Clock
8, // P2_0 Serial Data
11, // P2_3 Data/Command
2, // P1_0 Reset
9, // P2_1 Backlight
PUSH2); // Push Button 2
}
//#if defined(__MSP430G2553__) // LaunchPad MSP430G2553 specific
//LCD_5110::LCD_5110() {
// LCD_5110(P2_2, // Chip Select
// P2_4, // Serial Clock
// P2_0, // Serial Data
// P2_3, // Data/Command
// P1_0, // Reset
// P2_1, // Backlight
// PUSH2); // Push Button 2
//}
//#elif defined(__MSP430G2452__) // LaunchPad MSP430G2452 specific
//LCD_5110::LCD_5110() {
// LCD_5110(P2_2, // Chip Select
// P2_4, // Serial Clock
// P2_0, // Serial Data
// P2_3, // Data/Command
// P1_0, // Reset
// P2_1, // Backlight
// PUSH2); // Push Button 2
//}
//#elif defined(__LM4F120H5QR__) // StellarPad LM4F specific
//LCD_5110::LCD_5110() {
// LCD_5110(PA_7, // Chip Select
// PA_3, // Serial Clock
// PA_5, // Serial Data
// PA_2, // Data/Command
// PB_5, // Reset
// PA_6, // Backlight
// PUSH2); // Push Button 2
//}
//#else
//#error Platform not supported
//#endif
LCD_5110::LCD_5110(uint8_t pinChipSelect, uint8_t pinSerialClock, uint8_t pinSerialData, uint8_t pinDataCommand, uint8_t pinReset, uint8_t pinBacklight, uint8_t pinPushButton) {
_pinChipSelect = pinChipSelect;
_pinSerialClock = pinSerialClock;
_pinSerialData = pinSerialData;
_pinDataCommand = pinDataCommand;
_pinReset = pinReset;
_pinBacklight = pinBacklight;
_pinPushButton = pinPushButton;
}
void LCD_5110::write(uint8_t dataCommand, uint8_t c) {
digitalWrite(_pinDataCommand, dataCommand);
digitalWrite(_pinChipSelect, LOW);
shiftOut(_pinSerialData, _pinSerialClock, MSBFIRST, c);
digitalWrite(_pinChipSelect, HIGH);
}
void LCD_5110::setXY(uint8_t x, uint8_t y) {
write(_commandLCD, 0x40 | y);
write(_commandLCD, 0x80 | x);
}
void LCD_5110::begin() {
pinMode(_pinChipSelect, OUTPUT);
pinMode(_pinReset, OUTPUT);
pinMode(_pinDataCommand, OUTPUT);
pinMode(_pinSerialData, OUTPUT);
pinMode(_pinSerialClock, OUTPUT);
pinMode(_pinBacklight, OUTPUT);
pinMode(_pinPushButton, INPUT_PULLUP);
digitalWrite(_pinDataCommand, LOW);
delay(30);
digitalWrite(_pinReset, LOW);
delay(100); // as per 8.1 Initialisation
digitalWrite(_pinReset, HIGH);
write(_commandLCD, 0x21); // chip is active, horizontal addressing, use extended instruction set
write(_commandLCD, 0xc8); // write VOP to register: 0xC8 for 3V — try other values
write(_commandLCD, 0x12); // set Bias System 1:48
write(_commandLCD, 0x20); // chip is active, horizontal addressing, use basic instruction set
write(_commandLCD, 0x09); // temperature control
write(_commandLCD, 0x0c); // normal mode
delay(10);
clear();
_font = 0;
setBacklight(false);
}
String LCD_5110::WhoAmI() {
return "LCD Nokia 5110";
}
void LCD_5110::clear() {
setXY(0, 0);
for (uint16_t i=0; i<6*84; i++) write(_dataLCD, 0x00);
setXY(0, 0);
}
void LCD_5110::setBacklight(boolean b) {
digitalWrite(_pinBacklight, b ? LOW : HIGH);
}
void LCD_5110::setFont(uint8_t font) {
_font = font;
}
void LCD_5110::text(uint8_t x, uint8_t y, String s) {
uint8_t i;
uint8_t j;
if (_font==0) {
setXY(6*x, y);
for (j=0; j<s.length(); j++) {
for (i=0; i<5; i++) write(_dataLCD, Terminal6x8[s.charAt(j)-' '][i]);
write(_dataLCD, 0x00);
}
}
else if (_font==1) {
setXY(6*x, y);
for (j=0; j<s.length(); j++) {
for (i=0; i<11; i++) write(_dataLCD, Terminal11x16[s.charAt(j)-' '][2*i]);
write(_dataLCD, 0x00);
}
setXY(6*x, y+1);
for (j=0; j<s.length(); j++) {
for (i=0; i<11; i++) write(_dataLCD, Terminal11x16[s.charAt(j)-' '][2*i+1]);
write(_dataLCD, 0x00);
}
}
}
boolean LCD_5110::getButton() {
if (digitalRead(_pinPushButton)==LOW) {
while (digitalRead(_pinPushButton)==LOW); // debounce
return true;
} else {
return false;
}
}