Skip to content

Commit 8105683

Browse files
author
Rei Vilo
committed
Two examples for Nokia 5110 and LCD BoosterPack screens
Nokia 5110 screen LCD BoosterPack = Nokia 7110 screen
1 parent 8555fa0 commit 8105683

File tree

16 files changed

+1368
-0
lines changed

16 files changed

+1368
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//
2+
// LCD_5110.cpp
3+
// Library C++ code
4+
// ----------------------------------
5+
// Developed with embedXcode
6+
//
7+
// Project LCD 5110
8+
// Created by Rei VILO on 28/05/12
9+
// Copyright (c) 2012 http://embeddedcomputing.weebly.com
10+
// Licence CC = BY SA NC
11+
//
12+
13+
#include "LCD_5110.h"
14+
15+
const uint8_t _commandLCD = 0x00;
16+
const uint8_t _dataLCD = 0x01;
17+
18+
uint8_t _pinReset;
19+
uint8_t _pinSerialData;
20+
uint8_t _pinBacklight;
21+
uint8_t _pinChipSelect;
22+
uint8_t _pinDataCommand;
23+
uint8_t _pinSerialClock;
24+
uint8_t _pinPushButton;
25+
26+
27+
LCD_5110::LCD_5110() {
28+
LCD_5110(P2_2, // Chip Select
29+
P2_4, // Serial Clock
30+
P2_0, // Serial Data
31+
P2_3, // Data/Command
32+
P1_0, // Reset
33+
P2_1, // Backlight
34+
PUSH2); // Push Button 2
35+
}
36+
37+
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) {
38+
_pinChipSelect = pinChipSelect;
39+
_pinSerialClock = pinSerialClock;
40+
_pinSerialData = pinSerialData;
41+
_pinDataCommand = pinDataCommand;
42+
_pinReset = pinReset;
43+
_pinBacklight = pinBacklight;
44+
_pinPushButton = pinPushButton;
45+
}
46+
47+
void LCD_5110::write(uint8_t dataCommand, uint8_t c) {
48+
digitalWrite(_pinDataCommand, dataCommand);
49+
digitalWrite(_pinChipSelect, LOW);
50+
shiftOut(_pinSerialData, _pinSerialClock, MSBFIRST, c);
51+
digitalWrite(_pinChipSelect, HIGH);
52+
}
53+
54+
void LCD_5110::setXY(uint8_t x, uint8_t y) {
55+
write(_commandLCD, 0x40 | y);
56+
write(_commandLCD, 0x80 | x);
57+
}
58+
59+
void LCD_5110::begin() {
60+
pinMode(_pinChipSelect, OUTPUT);
61+
pinMode(_pinReset, OUTPUT);
62+
pinMode(_pinDataCommand, OUTPUT);
63+
pinMode(_pinSerialData, OUTPUT);
64+
pinMode(_pinSerialClock, OUTPUT);
65+
pinMode(_pinBacklight, OUTPUT);
66+
pinMode(_pinPushButton, INPUT_PULLUP);
67+
68+
digitalWrite(_pinDataCommand, LOW);
69+
delay(30);
70+
digitalWrite(_pinReset, LOW);
71+
delay(100); // as per 8.1 Initialisation
72+
digitalWrite(_pinReset, HIGH);
73+
74+
write(_commandLCD, 0x21); // chip is active, horizontal addressing, use extended instruction set
75+
write(_commandLCD, 0xc8); // write VOP to register: 0xC8 for 3V — try other values
76+
write(_commandLCD, 0x12); // set Bias System 1:48
77+
write(_commandLCD, 0x20); // chip is active, horizontal addressing, use basic instruction set
78+
write(_commandLCD, 0x09); // temperature control
79+
write(_commandLCD, 0x0c); // normal mode
80+
delay(10);
81+
82+
clear();
83+
_font = 0;
84+
setBacklight(false);
85+
}
86+
87+
String LCD_5110::WhoAmI() {
88+
return "LCD Nokia 5110";
89+
}
90+
91+
void LCD_5110::clear() {
92+
setXY(0, 0);
93+
for (uint16_t i=0; i<6*84; i++) write(_dataLCD, 0x00);
94+
setXY(0, 0);
95+
}
96+
97+
void LCD_5110::setBacklight(boolean b) {
98+
digitalWrite(_pinBacklight, b ? LOW : HIGH);
99+
}
100+
101+
void LCD_5110::setFont(uint8_t font) {
102+
_font = font;
103+
}
104+
105+
void LCD_5110::text(uint8_t x, uint8_t y, String s) {
106+
uint8_t i;
107+
uint8_t j;
108+
109+
if (_font==0) {
110+
setXY(6*x, y);
111+
for (j=0; j<s.length(); j++) {
112+
for (i=0; i<5; i++) write(_dataLCD, Terminal6x8[s.charAt(j)-' '][i]);
113+
write(_dataLCD, 0x00);
114+
}
115+
}
116+
else if (_font==1) {
117+
setXY(6*x, y);
118+
for (j=0; j<s.length(); j++) {
119+
for (i=0; i<11; i++) write(_dataLCD, Terminal11x16[s.charAt(j)-' '][2*i]);
120+
write(_dataLCD, 0x00);
121+
}
122+
123+
setXY(6*x, y+1);
124+
for (j=0; j<s.length(); j++) {
125+
for (i=0; i<11; i++) write(_dataLCD, Terminal11x16[s.charAt(j)-' '][2*i+1]);
126+
write(_dataLCD, 0x00);
127+
}
128+
}
129+
}
130+
131+
boolean LCD_5110::getButton() {
132+
if (digitalRead(_pinPushButton)==LOW) {
133+
while (digitalRead(_pinPushButton)==LOW); // debounce
134+
return true;
135+
} else {
136+
return false;
137+
}
138+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// LCD_5110.h
3+
// Library header
4+
// ----------------------------------
5+
// Developed with embedXcode
6+
//
7+
// Project LCD 5110
8+
// Created by Rei VILO on 28/05/12
9+
// Copyright (c) 2012 http://embeddedcomputing.weebly.com
10+
// Licence CC = BY SA NC
11+
//
12+
13+
// Core library
14+
#if defined (__AVR_ATmega328P__) || defined(__AVR_ATmega2560__) // Arduino specific
15+
#include "WProgram.h" // #include "Arduino.h" for Arduino 1.0
16+
#elif defined(__32MX320F128H__) || defined(__32MX795F512L__) // chipKIT specific
17+
#include "WProgram.h"
18+
#elif defined(__AVR_ATmega644P__) // Wiring specific
19+
#include "Wiring.h"
20+
#elif defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific
21+
#include "Energia.h"
22+
#elif defined(MCU_STM32F103RB) || defined(MCU_STM32F103ZE) || defined(MCU_STM32F103CB) || defined(MCU_STM32F103RE) // Maple specific
23+
#include "WProgram.h"
24+
#endif
25+
26+
#ifndef LCD_5110_h
27+
#define LCD_5110_h
28+
29+
#include "Terminal6.h"
30+
#include "Terminal12.h"
31+
32+
class LCD_5110 {
33+
public:
34+
LCD_5110();
35+
LCD_5110(uint8_t pinChipSelect, uint8_t pinSerialClock, uint8_t pinSerialData, uint8_t pinDataCommand, uint8_t pinReset, uint8_t pinBacklight, uint8_t pinPushButton);
36+
void begin();
37+
String WhoAmI();
38+
void clear();
39+
void setBacklight(boolean b=true);
40+
void setFont(uint8_t font=0);
41+
uint8_t fontX();
42+
uint8_t fontY();
43+
void text(uint8_t x, uint8_t y, String s);
44+
boolean getButton();
45+
46+
private:
47+
void setXY(uint8_t x, uint8_t y);
48+
void write(uint8_t dataCommand, uint8_t c);
49+
uint8_t _font;
50+
};
51+
52+
#endif
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// LCD_5110_main.pde
3+
// Sketch
4+
// ----------------------------------
5+
// Developed with embedXcode
6+
//
7+
// Project LCD 5110
8+
// Created by Rei VILO on 28/05/12
9+
// Copyright (c) 2012 http://embeddedcomputing.weebly.com
10+
// Licence CC = BY SA NC
11+
//
12+
13+
// Core library
14+
#if defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific
15+
#include "Energia.h"
16+
#else
17+
#error Board not supported
18+
#endif
19+
20+
// Include application, user and local libraries
21+
#include "LCD_5110.h"
22+
#include "Thermometer_430.h"
23+
24+
// Variables
25+
//LCD_5110 myScreen(P2_4, P2_3, P2_2, P2_1, P2_0, P2_5, PUSH2);
26+
27+
LCD_5110 myScreen;
28+
29+
//#define _pinChipSelect P2_4
30+
//#define _pinSerialClock P2_3
31+
//#define _pinSerialData P2_2
32+
//#define _pinDataCommand P2_1
33+
//#define _pinReset P2_0
34+
//#define _pinBacklight P2_5
35+
//#define _pinPushButton PUSH2
36+
//
37+
//LCD_5110(P2_2, // Chip Select *
38+
// P2_4, // Serial Clock *
39+
// P2_0, // Serial Data *
40+
// P2_3, // Data/Command *
41+
// P1_0, // Reset *
42+
// P2_1, // Backlight
43+
// PUSH2); // Push Button 0
44+
45+
46+
Thermometer_430 myThermometer;
47+
boolean backlight = false;
48+
49+
50+
// Add setup code
51+
void setup() {
52+
myThermometer.begin();
53+
54+
myScreen.begin();
55+
56+
myScreen.setFont(1);
57+
myScreen.text(1, 1, "MSP430");
58+
myScreen.setFont(0);
59+
myScreen.text(0, 5, "1234567890abcd");
60+
61+
delay(2000);
62+
myScreen.clear();
63+
myScreen.text(2, 0, "Thermometer");
64+
myScreen.text(0, 5, "off");
65+
66+
}
67+
68+
// Display mask
69+
char display[8] = {' ', ' ', ' ', '.', ' ', 0x7f, 'C', 0x00};
70+
71+
72+
// Add loop code
73+
void loop() {
74+
if (myScreen.getButton()) {
75+
backlight = ~backlight;
76+
myScreen.setFont(0);
77+
myScreen.text(0, 5, backlight ? "on " : "off");
78+
myScreen.setBacklight(backlight);
79+
}
80+
81+
myThermometer.get();
82+
83+
// Temperature display
84+
int32_t number = myThermometer.temperatureX10();
85+
86+
boolean flag = (number<0);
87+
if (flag) number = -number;
88+
89+
display[4] = 0x30 + (number%10);
90+
number /= 10;
91+
display[2] = 0x30 + (number%10);
92+
number /= 10;
93+
if (number>0) {
94+
display[1] = 0x30 + (number%10);
95+
} else if (flag) {
96+
display[1] = '-';
97+
flag = false;
98+
} else {
99+
display[1] = ' ';
100+
}
101+
number /= 10;
102+
if (number>0) display[0] = 0x30 + (number%10);
103+
else if (flag) display[0] = '-';
104+
else display[0] = ' ';
105+
106+
myScreen.setFont(1);
107+
myScreen.text(0, 2, display);
108+
109+
delay(500);
110+
}
111+
112+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
LCD 5110
3+
Read me
4+
----------------------------------
5+
Developed with embedXcode
6+
7+
Project LCD BoosterPack
8+
Created by Rei VILO on 28/05/12
9+
Copyright (c) 2012 http://embeddedcomputing.weebly.com
10+
Licence CC = BY SA NC
11+
12+
13+
Based on LCD BoosterPack by SugarAddict
14+
Uses GLCD fonts
15+
Push button on screen to turn backlight on / off
16+
17+
18+
References
19+
----------------------------------
20+
21+
• PCD8544 — 48 × 84 pixels matrix LCD controller/driver
22+
23+
• Fonts generated with MikroElektronika GLCD Font Creator 1.2.0.0
24+
http://www.mikroe.com
25+
26+
27+
28+
Developed with embedXcode
29+
----------------------------------
30+
Embedded Computing Template on Xcode 4.3
31+
© Rei VILO, 2010-2012
32+
CC = BY NC SA
33+
http:embedXcode.weebly.com/
34+

0 commit comments

Comments
 (0)