Arduino与Proteus仿真实例-Nokia5110显示屏驱动仿真

Nokia5110显示屏驱动仿真

Nokia5110使用飞利浦 PCD8544 液晶驱动器,显示屏大约只有 1.5” 直径,但由于带有背光而非常可读。该显示器由 84x48 单个像素组成,因此可以将其用于图形、文本或位图。这些显示器价格低廉,易于使用 ,只需要几个数字 I/O 引脚,并且功耗也相当低。

Nokia5110的介绍已经在下面的文章中做了介绍,请参考:

1、仿真电路原理图

在这里插入图片描述

2、仿真代码实现

本实例使用到如下开源库:

Adafruit-PCD8544-Nokia-5110-LCD-library示例代码如下:

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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
This is an example sketch for our Monochrome Nokia 5110 LCD Displays

Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/338

These displays use SPI to communicate, 4 or 5 pins are required to
interface

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
#include <SPI.h>
#include <Adafruit\_GFX.h>
#include <Adafruit\_PCD8544.h>

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit\_PCD8544(7, 6, 5, 4, 3);


#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16\_GLCD\_HEIGHT 16
#define LOGO16\_GLCD\_WIDTH 16

static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ 0B00000000, 0B11000000,
0B00000001, 0B11000000,
0B00000001, 0B11000000,
0B00000011, 0B11100000,
0B11110011, 0B11100000,
0B11111110, 0B11111000,
0B01111110, 0B11111111,
0B00110011, 0B10011111,
0B00011111, 0B11111100,
0B00001101, 0B01110000,
0B00011011, 0B10100000,
0B00111111, 0B11100000,
0B00111111, 0B11110000,
0B01111100, 0B11110000,
0B01110000, 0B01110000,
0B00000000, 0B00110000 };

void testdrawbitmap(const uint8\_t \*bitmap, uint8\_t w, uint8\_t h) {
uint8\_t icons[NUMFLAKES][3];
randomSeed(666); // whatever seed

// initialize
for (uint8\_t f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;

Serial.print("x: ");
Serial.print(icons[f][XPOS], DEC);
Serial.print(" y: ");
Serial.print(icons[f][YPOS], DEC);
Serial.print(" dy: ");
Serial.println(icons[f][DELTAY], DEC);
}

while (1) {
// draw each icon
for (uint8\_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
}
display.display();
delay(200);

while(Serial.available()) {
switch (Serial.read()) {
case 'w':display.setContrast(display.getContrast() + 1);
break;
case 's':if(display.getContrast()) display.setContrast(display.getContrast() - 1);
break;
case 'e':display.setBias(display.getBias() + 1);
break;
case 'd':if(display.getBias()) display.setBias(display.getBias() - 1);
break;
case 'R':display.setReinitInterval(10);
break;
case 'r':display.initDisplay();
display.setReinitInterval(0);
break;
}
}
Serial.print("contrast (w/s): 0x");
Serial.print(display.getContrast(), HEX);
Serial.print(" bias (e/d): 0x");
Serial.print(display.getBias(), HEX);
Serial.print(" reinitialize display (r/R): 0x");
Serial.print(display.getReinitInterval(), HEX);
Serial.print(" \r");

// then erase it + move it
for (uint8\_t f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
// move it
icons[f][YPOS] += icons[f][DELTAY];
// if its gone, reinit
if (icons[f][YPOS] > display.height()) {
icons[f][XPOS] = random(display.width());
icons[f][YPOS] = 0;
icons[f][DELTAY] = random(5) + 1;
}
}
}
}


void testdrawchar(void) {
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);

for (uint8\_t i=0; i < 168; i++) {
if (i == '\n') continue;
display.write(i);
//if ((i > 0) && (i % 14 == 0))
//display.println();
}
display.display();
}

void testdrawcircle(void) {
for (int16\_t i=0; i<display.height(); i+=2) {
display.drawCircle(display.width()/2, display.height()/2, i, BLACK);
display.display();
}
}

void testfillrect(void) {
uint8\_t color = 1;
for (int16\_t i=0; i<display.height()/2; i+=3) {
// alternate colors
display.fillRect(i, i, display.width()-i\*2, display.height()-i\*2, color%2);
display.display();
color++;
}
}

void testdrawtriangle(void) {
for (int16\_t i=0; i<min(display.width(),display.height())/2; i+=5) {
display.drawTriangle(display.width()/2, display.height()/2-i,
display.width()/2-i, display.height()/2+i,
display.width()/2+i, display.height()/2+i, BLACK);
display.display();
}
}

void testfilltriangle(void) {
uint8\_t color = BLACK;
for (int16\_t i=min(display.width(),display.height())/2; i>0; i-=5) {
display.fillTriangle(display.width()/2, display.height()/2-i,
display.width()/2-i, display.height()/2+i,
display.width()/2+i, display.height()/2+i, color);
if (color == WHITE) color = BLACK;
else color = WHITE;
display.display();
}
}

void testdrawroundrect(void) {
for (int16\_t i=0; i<display.height()/2-2; i+=2) {
display.drawRoundRect(i, i, display.width()-2\*i, display.height()-2\*i, display.height()/4, BLACK);
display.display();
}
}

void testfillroundrect(void) {
uint8\_t color = BLACK;
for (int16\_t i=0; i<display.height()/2-2; i+=2) {
display.fillRoundRect(i, i, display.width()-2\*i, display.height()-2\*i, display.height()/4, color);
if (color == WHITE) color = BLACK;
else color = WHITE;
display.display();
}
}

void testdrawrect(void) {
for (int16\_t i=0; i<display.height()/2; i+=2) {
display.drawRect(i, i, display.width()-2\*i, display.height()-2\*i, BLACK);
display.display();
}
}

void testdrawline() {
for (int16\_t i=0; i<display.width(); i+=4) {
display.drawLine(0, 0, i, display.height()-1, BLACK);
display.display();
}
for (int16\_t i=0; i<display.height(); i+=4) {
display.drawLine(0, 0, display.width()-1, i, BLACK);
display.display();
}
delay(250);

display.clearDisplay();
for (int16\_t i=0; i<display.width(); i+=4) {
display.drawLine(0, display.height()-1, i, 0, BLACK);
display.display();
}
for (int8\_t i=display.height()-1; i>=0; i-=4) {
display.drawLine(0, display.height()-1, display.width()-1, i, BLACK);
display.display();
}
delay(250);

display.clearDisplay();
for (int16\_t i=display.width()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK);
display.display();
}
for (int16\_t i=display.height()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK);
display.display();
}
delay(250);

display.clearDisplay();
for (int16\_t i=0; i<display.height(); i+=4) {
display.drawLine(display.width()-1, 0, 0, i, BLACK);
display.display();
}
for (int16\_t i=0; i<display.width(); i+=4) {
display.drawLine(display.width()-1, 0, i, display.height()-1, BLACK);
display.display();
}
delay(250);
}

void setup() {
Serial.begin(9600);
Serial.println("PCD test");
display.begin();
// init done

// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(75);

display.display(); // show splashscreen
delay(2000);
display.clearDisplay(); // clears the screen and buffer

// draw a single pixel
display.drawPixel(10, 10, BLACK);
display.display();
delay(2000);
display.clearDisplay();

// draw many lines
testdrawline();
display.display();
delay(2000);
display.clearDisplay();

// draw rectangles
testdrawrect();
display.display();
delay(2000);
display.clearDisplay();

// draw multiple rectangles
testfillrect();
display.display();
delay(2000);
display.clearDisplay();

// draw mulitple circles
testdrawcircle();
display.display();
delay(2000);
display.clearDisplay();

// draw a circle, 10 pixel radius
display.fillCircle(display.width()/2, display.height()/2, 10, BLACK);
display.display();
delay(2000);
display.clearDisplay();

testdrawroundrect();
delay(2000);
display.clearDisplay();

testfillroundrect();
delay(2000);
display.clearDisplay();

testdrawtriangle();
delay(2000);
display.clearDisplay();

testfilltriangle();
delay(2000);
display.clearDisplay();

// draw the first ~12 characters in the font
testdrawchar();
display.display();
delay(2000);
display.clearDisplay();

// text display tests
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(BLACK);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.display();
delay(2000);

// rotation example
display.clearDisplay();
display.setRotation(1); // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further.
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Rotation");
display.setTextSize(2);
display.println("Example!");
display.display();
delay(2000);

// revert back to no rotation
display.setRotation(0);

// miniature bitmap display
display.clearDisplay();
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
display.display();

// invert the display
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);

// draw a bitmap icon and 'animate' movement
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT);
}


void loop() {

}

3、仿真结果

在这里插入图片描述

文章来源: https://iotsmart.blog.csdn.net/article/details/121942084