forked from espruino/EspruinoDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCD8544.js
50 lines (46 loc) · 1.41 KB
/
PCD8544.js
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
/* Copyright (c) 2013 Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. */
/*
Module for the PCD8544 controller in the Nokia 5110 LCD.
Just:
```
SPI1.setup({ sck:B3, mosi:B5 });
var g = require("PCD8544").connect(SPI1,B6,B7,B8, function() {
g.clear();
g.drawString("Hello",0,0);
g.drawLine(0,10,84,10);
g.flip();
});
```
*/
exports.connect = function(/*=SPI*/spi, /*=PIN*/dc, /*=PIN*/ce, /*=PIN*/rst, callback) {
var LCD = Graphics.createArrayBuffer(84,48,1,{vertical_byte:true});
setTimeout(function() {
dc.reset(); // cmd
digitalPulse(rst, 0, 10); // pulse reset low
setTimeout(function() {
spi.write(
[0x21, // fnset extended
0x80 | 0x3F, // setvop (experiment with 2nd val to get the right contrast)
0x14, // setbias 4
0x04 | 0x02, // temp control
0x20, // fnset normal
0x08 | 0x04], ce); // dispctl normal
if (callback!==undefined) callback();
}, 100);
}, 100);
LCD.flip = function () {
dc.reset(); // cmd
spi.write([0x40,0x80], ce); // X + Y addr (0,0)
dc.set(); // data
spi.write(this.buffer, ce);
};
LCD.setContrast = function(c) { // c between 0 and 1. 0.5 is default
dc.reset(); // cmd
spi.write(
[0x21, // fnset extended
0x80 | E.clip(c*0x7f,0,0x7f), // setvop
0x20, // fnset normal
0x08 | 0x04], ce); // dispctl normal
};
return LCD;
};