-
Notifications
You must be signed in to change notification settings - Fork 0
/
tm1638cc.asm
364 lines (309 loc) · 6.91 KB
/
tm1638cc.asm
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
;=======================================================================
; tm1638cc.asm
; Examples of usage for tm1638 library
; written by Ralf Jardon (cosmicos at gmx dot net), May-July 2017
;
; Comments related to the datasheet refer to version 1.3 (en)
;
; License: GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007
;
; Version: 1.0beta-1
;=======================================================================
.NOLIST
.INCLUDE "tm1638cc.h"
.INCLUDE "tm1638cc.mac"
.LIST
.LISTMAC
.CSEG
.ORG $0000
.INCLUDE "tm1638cc_interrupt_vectors.inc"; Interrupt Vectors
.ORG $100
;=======================================================================
; Initialisation
; THIS IS REQUIRED - DONT CHANGE
;=======================================================================
INIT:
ldi AKKU, HIGH(RAMEND) ; Initialize stack pointer
out SPH, AKKU
ldi AKKU, LOW(RAMEND)
out SPL, AKKU
rcall TM1638_INIT ; Initialize Ports, SPI & TM1638
;=======================================================================
; Mainloop
; EXAMPLES OF LIBRARY USAGE - You can change whatever you want
;=======================================================================
MAINLOOP:
rcall TM1638_CLEAR
ldi AKKU3, 0 ; Textblock "TM1638 DEMO"
rcall TM1638_PRINT_MOVETEXT
restart_loop:
rcall TM1638_CLEAR
ldi AKKU3, 6 ; Textblock "PLEASE PRESS A BUTTON"
rcall TM1638_PRINT_MOVETEXT
clr BUTTONS
not_pressed:
rcall TM1638_POLL_KEYPAD ; check buttons
tst BUTTONS
breq not_pressed
mov AKKU, BUTTONS
cpi AKKU, BUTTON8
brne b7;
; button8 pressed
rcall TM1638_CLEAR
ldi AKKU3, 1 ; Textblock "RUNNING LIGHTS"
rcall TM1638_PRINT_MOVETEXT
rcall TM1638_CLEAR
rcall TM1638_LEDS_L
rcall TM1638_LEDS_R
rjmp restart_loop
b7:
cpi AKKU, BUTTON7
brne b6;
; button7 pressed
rcall TM1638_CLEAR
ldi AKKU3, 3 ; Textblock "BINARY COUNTER"
rcall TM1638_PRINT_MOVETEXT
rcall TM1638_CLEAR
rcall TM1638_COUNT_BIN
rjmp restart_loop
b6:
cpi AKKU, BUTTON6
brne b5;
; button6 pressed
rcall TM1638_CLEAR
ldi AKKU3, 4 ; Textblock "HEXADECIMAL COUNTER"
rcall TM1638_PRINT_MOVETEXT
rcall TM1638_CLEAR
rcall TM1638_COUNT_HEX
rjmp restart_loop
b5:
cpi AKKU, BUTTON5
brne b4;
; button5 pressed
rcall TM1638_CLEAR
ldi AKKU3, 5 ; Textblock "DECIMAL COUNTER"
rcall TM1638_PRINT_MOVETEXT
rcall TM1638_CLEAR
rcall TM1638_COUNT_DEC
rjmp restart_loop
b4:
cpi AKKU, BUTTON4
brne b3;
; button4 pressed
rcall TM1638_CLEAR
ldi AKKU3, 2 ; Textblock "TWIST SEGMENTS"
rcall TM1638_PRINT_MOVETEXT
rcall TM1638_CLEAR
ldi COUNT, 3 ; twist cw
tw_loop:
rcall TM1638_TWIST_CW
dec COUNT
brne tw_loop
ldi COUNT, 3 ; twist ccw
tw_loop1:
rcall TM1638_TWIST_CCW
dec COUNT
brne tw_loop1
rcall TM1638_CLEAR
rjmp restart_loop
b3:
cpi AKKU, BUTTON3
brne b2;
; button3 pressed
rcall TM1638_CLEAR
ldi AKKU3, 7 ; Textblock "CODE COMES WITH GPL V3"
rcall TM1638_PRINT_MOVETEXT
rcall TM1638_CLEAR
rjmp restart_loop
b2:
cpi AKKU, BUTTON2
brne b1;
; button2 pressed
ldi AKKU3, 0 ; Textblock "LEDS DIM"
rcall TM1638_PRINT_TEXT
ldi AKKU2, 4
dm0_loop:
ldi COUNT, 7 ; DIM LEDs
dm_loop:
mov AKKU, COUNT
rcall TM1638_BRIGHTNESS
rcall Delay100ms
rcall Delay100ms
dec COUNT
brne dm_loop
dec AKKU2
brne dm0_loop
ldi AKKU, DISP_PWM_MASK ; restore brightness settings
rcall TM1638_BRIGHTNESS
rjmp restart_loop
b1:
; button1 pressed, back to the beginning "TM1638 DEMO"
rjmp MAINLOOP
;=======================================================================
; Functions for Mainloop
;=======================================================================
;
; LED chain right
;
TM1638_LEDS_R:
push COUNT
ldi COUNT, 8
ldi TM1638_GRID_BYTE, 0x01 ; first LED address
led_loop:
ldi TM1638_SEGM_BYTE, 1 ; LED ON
rcall TM1638_SEND_DATA ;
rcall Delay100ms
clr TM1638_SEGM_BYTE ; LED OFF
rcall TM1638_SEND_DATA ;
subi TM1638_GRID_BYTE, -2 ; next LED address
dec COUNT
brne led_loop
pop COUNT
ret
;
; LED chain left
;
TM1638_LEDS_L:
push COUNT
ldi COUNT, 8
ldi TM1638_GRID_BYTE, 0x0F ; first LED address
led_loop_l:
ldi TM1638_SEGM_BYTE, 1 ; LED ON
rcall TM1638_SEND_DATA ;
rcall Delay100ms
clr TM1638_SEGM_BYTE ; LED OFF
rcall TM1638_SEND_DATA ;
subi TM1638_GRID_BYTE, 2 ; next LED address
dec COUNT
brne led_loop_l
pop COUNT
ret
;
; binary counter
;
TM1638_COUNT_BIN:
push AKKU
clr AKKU
binloop:
rcall TM1638_PRINT_BIN ; print value in AKKU
rcall Delay100ms
inc AKKU
cpi AKKU, 0x00
brne binloop
pop AKKU
ret
;
; hexadecimal coutner
;
TM1638_COUNT_HEX:
push AKKU2
push AKKU3
ldi XL,HIGH(0)
ldi XH,LOW(0)
z1loop:
mov AKKU2, XL
mov AKKU3, XH
rcall TM1638_PRINT_HEX ; print values in AKKU2 and AKKU3
; as 16 bit number (LO and HI-Byte)
rcall Delay10ms
cpi XH, 11
breq stop1_counting
adiw XH:XL,1
brne z1loop
stop1_counting:
pop AKKU3
pop AKKU2
ret
;
; decimal counter
;
TM1638_COUNT_DEC:
push AKKU2
push AKKU3
ldi XL,HIGH(0)
ldi XH,LOW(0)
zloop:
mov AKKU2, XL
mov AKKU3, XH
rcall TM1638_PRINT_DEC ; print values in AKKU2 and AKKU3
; as 16 bit number (LO and HI-Byte)
rcall Delay10ms
cpi XH, 8
breq stop_counting
adiw XH:XL,1
brne zloop
stop_counting:
pop AKKU3
pop AKKU2
ret
;
; twist arround CW
;
TM1638_TWIST_CW:
push AKKU
push COUNT
ldi AKKU, 1
clr COUNT
clr TM1638_GRID_BYTE
twistloop:
mov TM1638_SEGM_BYTE, AKKU
rcall TM1638_SEND_DATA ; activates only one LED. Position
; is given by GRID_BYTE (DIGIT) and
; SEGM_BYTE (LED-SEGMENT)
subi TM1638_GRID_BYTE, -2
inc COUNT
cpi COUNT, 8
brne twistloop
rcall delay10ms
rcall delay10ms
clr TM1638_GRID_BYTE
rol AKKU
cpi AKKU, 0b01000000
brne twistloop
pop COUNT
pop AKKU
ret
;
; twist arround CCW
;
TM1638_TWIST_CCW:
push AKKU
push COUNT
ldi AKKU, 0b00100000
clr COUNT
clr TM1638_GRID_BYTE
twistloop2:
mov TM1638_SEGM_BYTE, AKKU
rcall TM1638_SEND_DATA ; activates only one LED. Position
; is given by GRID_BYTE (DIGIT) and
; SEGM_BYTE (LED-SEGMENT)
subi TM1638_GRID_BYTE, -2
inc COUNT
cpi COUNT, 8
brne twistloop2
rcall delay10ms
rcall delay10ms
clr TM1638_GRID_BYTE
ror AKKU
brcc twistloop2
pop COUNT
pop AKKU
ret
.INCLUDE "tm1638cc.inc"
.INCLUDE "tm1638cc_input.asm"
.INCLUDE "tm1638cc_delay.inc"
.INCLUDE "tm1638cc_font.inc"
MOVETEXT:
.db " TM1638 DEMO ",0 ; TEXT_BLOCK 0
.db " RUNNING LIGHT ",0 ; TEXT_BLOCK 1
.db " TWIST SEGMENTS ",0 ; TEXT_BLOCK 2
.db " BINARY COUNTER ",0 ; TEXT_BLOCK 3
.db " HEXADECIMAL COUNTER ",0 ; TEXT_BLOCK 4
.db " DECIMAL COUNTER ",0 ; TEXT_BLOCK 5
.db " PLEASE PRESS A BUTTON",0 ; TEXT_BLOCK 6
.db " CODE COMES WITH GPL V3 ",0 ; TEXT_BLOCK 7
PRINTTEXT:
.db "LEDS DIM",0,0 ; TEXT_BLOCK 0
.db "A BUTTON",0,0 ; TEXT_BLOCK 1
.db " ",0,0 ; TEXT_BLOCK 2
.EXIT