SHOW:
|
|
- or go back to the newest paste.
1 | - | function HD44780(write) { |
1 | + | function hd44780(write) { |
2 | // initialise | |
3 | write(0x33,1); | |
4 | write(0x32,1); | |
5 | write(0x28,1); | |
6 | write(0x0C,1); | |
7 | write(0x06,1); | |
8 | write(0x01,1); | |
9 | // add functions | |
10 | return { | |
11 | - | write : write, |
11 | + | write: write, |
12 | // clear screen | |
13 | - | clear : function() { write(0x01,1); }, |
13 | + | clear: function() { write(0x01,1); }, |
14 | // print text | |
15 | print : function(str) { | |
16 | for (var i=0;i<str.length;i++) | |
17 | write(Integer.valueOf(str.charAt(i))); | |
18 | }, | |
19 | // flashing block for the current cursor, or underline | |
20 | cursor : function(block) { write(block?0x0F:0x0E,1); }, | |
21 | // set cursor pos, top left = 0,0 | |
22 | setCursor : function(x,y) { var l=[0x00,0x40,0x14,0x54];write(0x80|(l[y]+x),1); }, | |
23 | // set special character 0..7, data is an array(8) of bytes, and then return to home addr | |
24 | createChar : function(ch, data) { | |
25 | write(0x40 | ((ch&7) << 3), 1); | |
26 | for (var i=0; i<8; i++) write(data[i]); | |
27 | write(0x80,1); | |
28 | } | |
29 | }; | |
30 | } | |
31 | ||
32 | function connect(/*=PIN*/_rs,/*=PIN*/_en,/*=PIN*/_d4,/*=PIN*/_d5,/*=PIN*/_d6,/*=PIN*/_d7) { | |
33 | var data = [_d7,_d6,_d5,_d4]; | |
34 | var rs = _rs; | |
35 | var en = _en; | |
36 | digitalWrite([rs,en], 0); | |
37 | var write = function(x, c) { | |
38 | digitalWrite(rs, c===undefined); | |
39 | digitalWrite(data, x>>4); | |
40 | digitalPulse(en, 1, 0.01); | |
41 | digitalWrite(data, x); | |
42 | digitalPulse(en, 1, 0.01); | |
43 | }; | |
44 | //return new HD44780(write); | |
45 | return write; | |
46 | } | |
47 | ||
48 | var connect = connect(A4,A5,A0,A7,A2,A3); | |
49 | - | var led = HD44780(connect); |
49 | + | var led = hd44780(connect); |
50 | ||
51 | - | lcd.print("Hello World!"); |
51 | + | led.print("Hello World!"); |