-
Notifications
You must be signed in to change notification settings - Fork 1
/
sed1520.py
103 lines (66 loc) · 2.77 KB
/
sed1520.py
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
"""
User mode device driver for display modules using
Seiko/Epson SED1520 display controllers.
Copyright (c) 2006 [email protected]
This file is released under the GNU Lesser General Public Licence.
See the file LICENSE for details.
"""
try:
import parallel # http://pyserial.sourceforge.net/pyparallel
class SED1520(object):
def __init__(self, dev = 0):
p = parallel.Parallel(dev)
self.setA0 = p.setAutoFeed # pin 14
self.setE1 = p.setInitOut # pin 16
self.setE2 = p.setSelect # pin 17
self.setData = p.setData # pins 2-9
self.W = 122
self.H = 32
self.init()
def init(self):
for chip in [1,2]:
self.selectChip(chip)
self.setE(0)
self.enableDisplay(0)
self.reset()
self.sendCommand(0xA0) # forward column addressing
self.sendCommand(0xA4) # static mode off
self.sendCommand(0xA9) # 1/32 duty cycle
self.enableDisplay(1)
self.setDisplayStartLine(0)
for page in xrange(4):
self.setPageAddress(page)
self.setColumnAddress(0)
self.writeDisplayData('\x00' * 61)
self.setPageAddress(0)
self.setColumnAddress(0)
def selectChip(self, chip):
self.setE = (self.setE1, self.setE2)[chip-1]
def sendCommand(self, cmd):
self.setA0(0)
self.setData(cmd)
self.setE(1)
self.setE(0)
def enableDisplay(self, enable=1):
self.sendCommand(0xAE + enable)
def setDisplayStartLine(self, address):
self.sendCommand(0xC0 + (address & 0x1F))
def setPageAddress(self, address):
self.sendCommand(0xB8 + (address & 0x3))
def setColumnAddress(self, address):
self.sendCommand(address & 0x7F)
def writeDisplayData(self, data):
self.setA0(1)
for d in data:
self.setData(ord(d))
self.setE(1)
self.setE(0)
def reset(self):
self.sendCommand(0xE2)
except: pass
if __name__ == '__main__':
d = SED1520(0)
d.selectChip(1)
d.writeDisplayData('\x55' * 61)
d.selectChip(2)
d.writeDisplayData('\x55' * 61)