Stefan Schuermans commited on 2012-06-28 20:42:22
Showing 1 changed files, with 98 additions and 11 deletions.
... | ... |
@@ -43,6 +43,12 @@ |
43 | 43 |
.def CNT = r17 |
44 | 44 |
.def DATA = r18 |
45 | 45 |
|
46 |
+; current mode |
|
47 |
+.def MODE = r19 |
|
48 |
+.equ MODE_ALL = 0 ; play all animations |
|
49 |
+.equ MODE_SINGLE = 1 ; play single animation only |
|
50 |
+.equ MODE_UNKNOWN = 0xFF ; unknown mode |
|
51 |
+ |
|
46 | 52 |
|
47 | 53 |
|
48 | 54 |
.DSEG |
... | ... |
@@ -159,12 +165,17 @@ ROW_OFF_LOOP: |
159 | 165 |
|
160 | 166 |
|
161 | 167 |
; play an animation N times (mode 0) or infinitely (mode 1) |
162 |
-; parameters: animation function, N |
|
168 |
+; parameters: animation function, N, animation number |
|
163 | 169 |
.MACRO PL_ANIM |
164 | 170 |
PL_ANIM_LOOP: |
171 |
+ ; play animation N times |
|
165 | 172 |
rcall_N @0,@1 - 1 |
166 |
- sbic MODE_SW_PIN,MODE_SW_BIT |
|
167 |
- rjmp PL_ANIM_LOOP |
|
173 |
+ ; read new mode |
|
174 |
+ ldi CNT,@2 |
|
175 |
+ rcall MODE_READ |
|
176 |
+ ; keep playing animation in mode 1 |
|
177 |
+ cpi MODE,MODE_SINGLE |
|
178 |
+ breq PL_ANIM_LOOP |
|
168 | 179 |
.ENDM |
169 | 180 |
|
170 | 181 |
|
... | ... |
@@ -641,25 +652,101 @@ ANIM_BW_WORM_LOOP: |
641 | 652 |
|
642 | 653 |
|
643 | 654 |
|
655 |
+; read mode from switch and (store animation number) |
|
656 |
+; input: MODE = old mode, CNT = animation number |
|
657 |
+; output: MODE = new mode |
|
658 |
+; changes: TMP, DATA |
|
659 |
+MODE_READ: |
|
660 |
+; read new mode (into DATA) |
|
661 |
+ ldi DATA,MODE_ALL |
|
662 |
+ sbic MODE_SW_PIN,MODE_SW_BIT |
|
663 |
+ ldi DATA,MODE_SINGLE |
|
664 |
+; mode was changed from all to single -> save animation number |
|
665 |
+ cpi MODE,MODE_ALL ; old mode not all -> do nothing |
|
666 |
+ brne MODE_READ_NOT_0_TO_1 |
|
667 |
+ cpi DATA,MODE_SINGLE ; new mode not single -> do nothing |
|
668 |
+ brne MODE_READ_NOT_0_TO_1 |
|
669 |
+ sbic EECR,EEPE ; EEPROM write ongoing -> do nothing |
|
670 |
+ rjmp MODE_READ_NOT_0_TO_1 |
|
671 |
+ ldi TMP,0<<EEPM1|0<<EEPM0 ; set EEPROM programming mode |
|
672 |
+ out EECR,TMP |
|
673 |
+ ldi TMP,0 ; set EEPROM address |
|
674 |
+ out EEARL,TMP |
|
675 |
+ mov TMP,CNT ; set EEPROM data to animation number |
|
676 |
+ com TMP ; with NOTed number in upper nibble |
|
677 |
+ swap TMP |
|
678 |
+ andi TMP,0xF0 |
|
679 |
+ or TMP,CNT |
|
680 |
+ out EEDR,TMP |
|
681 |
+ sbi EECR,EEMPE ; begin writing EEPROM |
|
682 |
+ sbi EECR,EEPE |
|
683 |
+MODE_READ_NOT_0_TO_1: |
|
684 |
+; remember new mode (in MODE) |
|
685 |
+ mov MODE,DATA |
|
686 |
+; done |
|
687 |
+ ret |
|
688 |
+ |
|
689 |
+ |
|
690 |
+ |
|
644 | 691 |
; main program |
645 | 692 |
MAIN: |
646 | 693 |
wdr |
647 | 694 |
|
648 | 695 |
; initialization |
696 |
+ ldi MODE,MODE_UNKNOWN ; unknown mode |
|
697 |
+ |
|
698 |
+; get number of fist animation from EEPROM (into CNT) |
|
699 |
+ ldi TMP,0 ; set EEPROM address |
|
700 |
+ out EEARL,TMP |
|
701 |
+ sbi EECR,EERE ; start EEPROM read |
|
702 |
+ in CNT,EEDR ; get read value |
|
703 |
+ mov TMP,CNT ; check if high nibble contains NOTed |
|
704 |
+ com TMP ; value |
|
705 |
+ swap TMP |
|
706 |
+ cp CNT,TMP |
|
707 |
+ brne MAIN_FIRST_ANIM_END |
|
708 |
+ andi CNT,0x0F ; throw away check value in high nibble |
|
709 |
+; jump to first animation |
|
710 |
+ cpi CNT,0 |
|
711 |
+ breq MAIN_FIRST_0 |
|
712 |
+ cpi CNT,1 |
|
713 |
+ breq MAIN_FIRST_1 |
|
714 |
+ cpi CNT,2 |
|
715 |
+ breq MAIN_FIRST_2 |
|
716 |
+ cpi CNT,3 |
|
717 |
+ breq MAIN_FIRST_3 |
|
718 |
+ cpi CNT,4 |
|
719 |
+ breq MAIN_FIRST_4 |
|
720 |
+ cpi CNT,5 |
|
721 |
+ breq MAIN_FIRST_5 |
|
722 |
+ cpi CNT,6 |
|
723 |
+ breq MAIN_FIRST_6 |
|
724 |
+ cpi CNT,7 |
|
725 |
+ breq MAIN_FIRST_7 |
|
726 |
+MAIN_FIRST_ANIM_END: |
|
727 |
+ |
|
649 | 728 |
|
650 | 729 |
MAIN_LOOP: |
651 | 730 |
wdr |
652 | 731 |
|
653 | 732 |
; main loop |
654 | 733 |
|
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 |
|
734 |
+MAIN_FIRST_0: |
|
735 |
+ PL_ANIM ANIM_BLINK,3,0 |
|
736 |
+MAIN_FIRST_1: |
|
737 |
+ PL_ANIM ANIM_WORM,3,1 |
|
738 |
+MAIN_FIRST_2: |
|
739 |
+ PL_ANIM ANIM_FLICKER,10,2 |
|
740 |
+MAIN_FIRST_3: |
|
741 |
+ PL_ANIM ANIM_BW_RUN,3,3 |
|
742 |
+MAIN_FIRST_4: |
|
743 |
+ PL_ANIM ANIM_FADE,2,4 |
|
744 |
+MAIN_FIRST_5: |
|
745 |
+ PL_ANIM ANIM_BW_WORM,3,5 |
|
746 |
+MAIN_FIRST_6: |
|
747 |
+ PL_ANIM ANIM_WOBBLE,5,6 |
|
748 |
+MAIN_FIRST_7: |
|
749 |
+ PL_ANIM ANIM_RUN,3,7 |
|
663 | 750 |
|
664 | 751 |
; bottom of main loop |
665 | 752 |
|
666 | 753 |