-
Notifications
You must be signed in to change notification settings - Fork 0
/
oled.s
235 lines (203 loc) · 2.75 KB
/
oled.s
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
SECTION code_user
PUBLIC _oled_init
PUBLIC _oled_normal
PUBLIC _oled_invert
PUBLIC _oled_test
PUBLIC _oled_clear
PUBLIC _oled_set_full_screen
PUBLIC _oled_draw_image
reset:
LD C,0x50
LD B,0x06
OUT (C),A
NOP
NOP
NOP
NOP
RES 2,B
OUT (C),A
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RET
command:
LD C,0x50
LD B,0x00
OUT (C),A
NOP
NOP
NOP
NOP
SET 1,B
OUT (C),A
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RET
oleddata:
LD C,0x50
LD B,0x01
OUT (C),A
NOP
NOP
NOP
NOP
SET 1,B
OUT (C),A
NOP
NOP
RET
_oled_init:
call reset
ld HL, SEQUENCE
initloop:
LD A,(HL)
CP 0xFF
RET Z
CALL command
INC HL
JR initloop
_oled_invert:
LD A,0xA7
call command
ret
_oled_normal:
LD A,0xA6
call command
ret
_oled_set_full_screen:
LD A,0x20
CALL command
LD A,0x00
CALL command
LD A,0x21
CALL command
LD A,0x04
CALL command
LD A,0x83
CALL command
LD A,0x22
CALL command
LD A,0x00
CALL command
LD A,0x03
CALL command
LD A,0xB0
CALL command
LD A,0x10
CALL command
LD A,0x04
CALL command
_oled_draw_image:
POP BC ; get return address
POP HL ; get address of image data
PUSH HL ; put the stack back together
PUSH BC ; again
LD D,0
winloop:
LD A,(HL)
CALL oleddata
INC HL
LD A,(HL)
CALL oleddata
INC HL
DEC D
JR NZ,winloop
RET
_oled_clear:
LD A,0xB0
CALL command
CALL clearrow
LD A,0xB1
CALL command
CALL clearrow
LD A,0xB2
CALL command
CALL clearrow
LD A,0xB3
CALL command
CALL clearrow
RET
clearrow:
LD A,0x10
CALL command
LD A,0x04
CALL command
XOR A
LD D,0x80
clearloop:
CALL oleddata
DEC D
JR NZ, clearloop
RET
_oled_brightness:
POP HL ; return address
DEC SP
POP AF ; brightness
LD D,A
LD A,0x81
CALL command
ld A,D
call command
PUSH AF ; restore stack
INC SP
PUSH HL
ret
_oled_test:
LD A,0xB0
CALL command
LD A,0x10
CALL command
LD A,0x04
call command
XOR A
rowloop:
CALL oleddata
INC A
CP 0x80
RET Z
JR rowloop
SEQUENCE:
DB 0xAE, 0xD5, 0xA0, 0xA8
DB 0x1F, 0xD3, 0x00, 0xAD
DB 0x8E, 0xD8, 0x05, 0xA1
DB 0xC8, 0xDA, 0x12, 0x91
DB 0x3F, 0x3F, 0x3F, 0x3F
DB 0x81, 0x80, 0xD9, 0xD2
DB 0xDB, 0x34, 0xA6, 0xA4
DB 0xAF
DB 0xFF