Stefan Schuermans commited on 2012-06-10 10:55:19
Showing 1 changed files, with 33 additions and 110 deletions.
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
; bulb - BlinkenArea ultimate logo board |
2 |
-; version 1.0.0 date 2011-07-30 |
|
2 |
+; version 1.1.0 date 2012-06-10 |
|
3 | 3 |
; Copyright (C) 2011-2012 Stefan Schuermans <stefan@blinkenarea.org> |
4 | 4 |
; Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
5 | 5 |
|
... | ... |
@@ -15,14 +15,14 @@ |
15 | 15 |
; PB4: column 4 output (output, low) |
16 | 16 |
; PB5: column 5 output (output, low) |
17 | 17 |
; PB6: column 6 output (output, low) |
18 |
-; PB7: push button input (input, pull-up enabled) |
|
18 |
+; PB7: unused (input, pull-up enabled) |
|
19 | 19 |
; PD0: row 0 output (output, high) |
20 | 20 |
; PD1: row 1 output (output, high) |
21 | 21 |
; PD2: row 2 output (output, high) |
22 | 22 |
; PD3: row 3 output (output, high) |
23 | 23 |
; PD4: row 4 output (output, high) |
24 | 24 |
; PD5: row 5 output (output, high) |
25 |
-; PD6: unused (output, low) |
|
25 |
+; PD6: mode switch (input, pull-up enabled) |
|
26 | 26 |
|
27 | 27 |
|
28 | 28 |
|
... | ... |
@@ -33,8 +33,8 @@ |
33 | 33 |
; IO pins |
34 | 34 |
.equ COL_PORT = PORTB ; column outputs |
35 | 35 |
.equ ROW_PORT = PORTD ; row outputs |
36 |
-.equ BTN_PIN = PINB |
|
37 |
-.equ BTN_BIT = 7 |
|
36 |
+.equ MODE_SW_PIN = PIND |
|
37 |
+.equ MODE_SW_BIT = 6 |
|
38 | 38 |
|
39 | 39 |
|
40 | 40 |
|
... | ... |
@@ -105,8 +105,8 @@ NE: |
105 | 105 |
PIXEL @0 ; pixel 5 |
106 | 106 |
PIXEL @0 ; pixel 6 |
107 | 107 |
subi XL,7 ; XH not there on ATtiny2313 |
108 |
- lsr DATA ; ensure remaining bit stays |
|
109 |
- ; high (pull-up for button) |
|
108 |
+ lsr DATA ; ensure remaining bit stays high |
|
109 |
+ ; (pull-up for unused pin) |
|
110 | 110 |
com DATA |
111 | 111 |
out COL_PORT,DATA |
112 | 112 |
.ENDM |
... | ... |
@@ -151,13 +151,24 @@ NE: |
151 | 151 |
ROW_OFF_LOOP: |
152 | 152 |
dec TMP |
153 | 153 |
brne ROW_OFF_LOOP |
154 |
- ldi TMP,0x80 ; ensure remaining bit stays |
|
155 |
- ; high (pull-up for button) |
|
154 |
+ ldi TMP,0x80 ; ensure remaining bit stays high |
|
155 |
+ ; (pull-up for unused pin) |
|
156 | 156 |
out COL_PORT,TMP |
157 | 157 |
.ENDM |
158 | 158 |
|
159 | 159 |
|
160 | 160 |
|
161 |
+; play an animation N times (mode 0) or infinitely (mode 1) |
|
162 |
+; parameters: animation function, N |
|
163 |
+.MACRO PL_ANIM |
|
164 |
+PL_ANIM_LOOP: |
|
165 |
+ rcall_N @0, @1 - 1 |
|
166 |
+ sbic MODE_SW_PIN,MODE_SW_BIT |
|
167 |
+ rjmp PL_ANIM_LOOP |
|
168 |
+.ENDM |
|
169 |
+ |
|
170 |
+ |
|
171 |
+ |
|
161 | 172 |
.CSEG |
162 | 173 |
.ORG 0x000 |
163 | 174 |
rjmp ENTRY ; RESET |
... | ... |
@@ -200,9 +211,9 @@ ENTRY: |
200 | 211 |
out PORTB,TMP |
201 | 212 |
ldi TMP,0x7F |
202 | 213 |
out DDRB,TMP |
203 |
- ldi TMP,0x3F ; PD[0-5] to output, high - PD6 to output, low |
|
214 |
+ ldi TMP,0x7F ; PD[0-5] to output, high - PD6 to input, pull-up enabled |
|
204 | 215 |
out PORTD,TMP |
205 |
- ldi TMP,0x7F |
|
216 |
+ ldi TMP,0x3F |
|
206 | 217 |
out DDRD,TMP |
207 | 218 |
; initialize stack pointer |
208 | 219 |
ldi TMP,RAMEND |
... | ... |
@@ -217,13 +228,6 @@ ENTRY: |
217 | 228 |
; disable analog comparator |
218 | 229 |
ldi TMP,1<<ACD |
219 | 230 |
out ACSR,TMP |
220 |
-; enable pin change interrupt for button |
|
221 |
-; to wake up from sleep |
|
222 |
- in TMP,GIMSK |
|
223 |
- ori TMP,1<<PCIE |
|
224 |
- out GIMSK,TMP |
|
225 |
- ldi TMP,1<<PCINT7 |
|
226 |
- out PCMSK,TMP |
|
227 | 231 |
; jump to main program |
228 | 232 |
rjmp MAIN |
229 | 233 |
|
... | ... |
@@ -275,7 +279,7 @@ ROW_GRAY: |
275 | 279 |
; input: FRAME = pixel data (0..15) |
276 | 280 |
; output: - |
277 | 281 |
; changes: TMP, CNT, DATA, X |
278 |
-; cycles: 43676 (including rcall and ret) |
|
282 |
+; cycles: 43682 (including rcall and ret) |
|
279 | 283 |
; time: 5.5ms |
280 | 284 |
OUT_FRAME: |
281 | 285 |
wdr |
... | ... |
@@ -286,6 +290,8 @@ OUT_FRAME_LOOP: |
286 | 290 |
mov TMP,CNT ; select row |
287 | 291 |
com TMP |
288 | 292 |
andi TMP,0x3F |
293 |
+ ori TMP,0x40 ; ensure bit 6 stays high |
|
294 |
+ ; (pull-up for switch input) |
|
289 | 295 |
out ROW_PORT,TMP |
290 | 296 |
rcall ROW_GRAY ; display row |
291 | 297 |
subi XL,-7 ; ptr to next row |
... | ... |
@@ -298,86 +304,7 @@ OUT_FRAME_LOOP: |
298 | 304 |
|
299 | 305 |
|
300 | 306 |
|
301 |
-; handle on/off button |
|
302 |
-; input: - |
|
303 |
-; output: - |
|
304 |
-; changes: TMP, CNT |
|
305 |
-; time: usually very short, but may suspend execution |
|
306 |
-BUTTON: |
|
307 |
-; exit if button not pressed |
|
308 |
-; require stable press for about 50 ms |
|
309 |
- clr CNT ; loop 65536 times |
|
310 |
- clr TMP |
|
311 |
-BUTTON_CHECK_PRESS_LOOP: |
|
312 |
- wdr |
|
313 |
- sbic BTN_PIN,BTN_BIT ; not pressed -> leave |
|
314 |
- ret |
|
315 |
- dec TMP |
|
316 |
- brne BUTTON_CHECK_PRESS_LOOP |
|
317 |
- dec CNT |
|
318 |
- brne BUTTON_CHECK_PRESS_LOOP |
|
319 |
-; wait for button to be released |
|
320 |
-; require stable release for about 50 ms |
|
321 |
-BUTTON_WAIT_RELEASE: |
|
322 |
- clr CNT ; loop 65536 times |
|
323 |
- clr TMP |
|
324 |
-BUTTON_WAIT_RELEASE_LOOP: |
|
325 |
- wdr |
|
326 |
- sbis BTN_PIN,BTN_BIT ; pressed -> start over |
|
327 |
- rjmp BUTTON_WAIT_RELEASE |
|
328 |
- dec TMP |
|
329 |
- brne BUTTON_WAIT_RELEASE_LOOP |
|
330 |
- dec CNT |
|
331 |
- brne BUTTON_WAIT_RELEASE_LOOP |
|
332 |
-; disable watchdog |
|
333 |
- cli |
|
334 |
- wdr |
|
335 |
- in TMP,WDTCR |
|
336 |
- ori TMP,1<<WDCE|1<<WDE |
|
337 |
- out WDTCR,TMP |
|
338 |
- andi TMP,~(1<<WDCE|1<<WDE) |
|
339 |
- out WDTCR,TMP |
|
340 |
- wdr |
|
341 |
- sei |
|
342 |
-; sleep |
|
343 |
- in TMP,MCUCR ; configure power-down sleep |
|
344 |
- andi TMP,~(1<<SM1) |
|
345 |
- ori TMP,1<<SE|1<<SM0 |
|
346 |
- out MCUCR,TMP |
|
347 |
- sleep ; go to sleep |
|
348 |
- in TMP,MCUCR ; configure no sleep mode |
|
349 |
- andi TMP,~(1<<SE) |
|
350 |
- out MCUCR,TMP |
|
351 |
-; enable watchdog |
|
352 |
- cli |
|
353 |
- wdr |
|
354 |
- in TMP,WDTCR |
|
355 |
- ori TMP,1<<WDCE|1<<WDE |
|
356 |
- out WDTCR,TMP |
|
357 |
- andi TMP,~(1<<WDCE) |
|
358 |
- out WDTCR,TMP |
|
359 |
- wdr |
|
360 |
- sei |
|
361 |
-; wait for button to be released |
|
362 |
-; require stable release for about 50 ms |
|
363 |
-BUTTON_WAIT2_RELEASE: |
|
364 |
- clr CNT ; loop 65536 times |
|
365 |
- clr TMP |
|
366 |
-BUTTON_WAIT2_RELEASE_LOOP: |
|
367 |
- wdr |
|
368 |
- sbis BTN_PIN,BTN_BIT ; pressed -> start over |
|
369 |
- rjmp BUTTON_WAIT2_RELEASE |
|
370 |
- dec TMP |
|
371 |
- brne BUTTON_WAIT2_RELEASE_LOOP |
|
372 |
- dec CNT |
|
373 |
- brne BUTTON_WAIT2_RELEASE_LOOP |
|
374 |
-; done |
|
375 |
- ret |
|
376 |
- |
|
377 |
- |
|
378 |
- |
|
379 | 307 |
; output a frame for some time |
380 |
-; also handles on/off button |
|
381 | 308 |
; input: FRAME = pixel data (0..15) |
382 | 309 |
; TMP = time to show frame (1..255, in 5.5 ms steps) |
383 | 310 |
; output: - |
... | ... |
@@ -389,7 +316,6 @@ OUT_FRAME_TIME: |
389 | 316 |
push CNT |
390 | 317 |
push DATA |
391 | 318 |
rcall OUT_FRAME ; 5.5 ms |
392 |
- rcall BUTTON |
|
393 | 319 |
pop DATA |
394 | 320 |
pop CNT |
395 | 321 |
pop TMP |
... | ... |
@@ -721,22 +647,19 @@ MAIN: |
721 | 647 |
|
722 | 648 |
; initialization |
723 | 649 |
|
724 |
-; enable interrupts |
|
725 |
- sei |
|
726 |
- |
|
727 | 650 |
MAIN_LOOP: |
728 | 651 |
wdr |
729 | 652 |
|
730 | 653 |
; main loop |
731 | 654 |
|
732 |
- rcall_N ANIM_BLINK,3 |
|
733 |
- rcall_N ANIM_WORM,3 |
|
734 |
- rcall_N ANIM_FLICKER,10 |
|
735 |
- rcall_N ANIM_BW_RUN,3 |
|
736 |
- rcall_N ANIM_FADE,2 |
|
737 |
- rcall_N ANIM_BW_WORM,3 |
|
738 |
- rcall_N ANIM_WOBBLE,5 |
|
739 |
- rcall_N ANIM_RUN,3 |
|
655 |
+ PL_ANIM ANIM_BLINK,3 |
|
656 |
+ PL_ANIM ANIM_WORM,3 |
|
657 |
+ PL_ANIM ANIM_FLICKER,10 |
|
658 |
+ PL_ANIM ANIM_BW_RUN,3 |
|
659 |
+ PL_ANIM ANIM_FADE,2 |
|
660 |
+ PL_ANIM ANIM_BW_WORM,3 |
|
661 |
+ PL_ANIM ANIM_WOBBLE,5 |
|
662 |
+ PL_ANIM ANIM_RUN,3 |
|
740 | 663 |
|
741 | 664 |
; bottom of main loop |
742 | 665 |
|
743 | 666 |