author | Tero Marttila <terom@fixme.fi> |
Sat, 08 May 2010 17:27:27 +0300 | |
changeset 18 | 79b25e81721f |
parent 17 | a7c668003a19 |
child 19 | 1e00790c5029 |
permissions | -rw-r--r-- |
3 | 1 |
.nolist |
2 |
.include "m168def.inc" ; Same family as 328P |
|
3 |
.list |
|
4 |
||
5 |
;; Interrupt Vector |
|
6 |
.org 0x00 |
|
7 |
rjmp init |
|
8 |
||
18 | 9 |
.org OC1Aaddr |
10 |
; Timer/Counter1 Overflow |
|
11 |
rjmp Timer_OC1A |
|
12 |
||
3 | 13 |
.org SPIaddr |
14 |
rjmp SPI_Interrupt |
|
15 |
||
8 | 16 |
.org ADCCaddr |
17 |
rjmp ADC_Interrupt |
|
18 |
||
3 | 19 |
;; SPI |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
20 |
.include "spi.inc" |
3 | 21 |
|
22 |
;; LCD |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
23 |
.include "led7seg.inc" |
3 | 24 |
|
8 | 25 |
;; ADC |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
26 |
.include "adc.inc" |
8 | 27 |
|
18 | 28 |
;; Timer |
29 |
.include "timer.inc" |
|
30 |
||
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
31 |
;; Utils |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
32 |
.include "delay.inc" |
7 | 33 |
|
6 | 34 |
;; Count down from 9 |
35 |
; Returns once we've hit zero |
|
36 |
Main_Countdown: |
|
16 | 37 |
; init from F |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
38 |
ldi r24, LED7_F |
6 | 39 |
|
15
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
40 |
_count_loop: |
6 | 41 |
; display |
42 |
mov r16, r24 |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
43 |
rcall LED7_Show |
6 | 44 |
|
45 |
; exit if zero |
|
46 |
tst r24 |
|
15
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
47 |
breq _count_end |
6 | 48 |
|
49 |
; count down |
|
50 |
dec r24 |
|
51 |
||
52 |
; wait... |
|
53 |
rcall Delay_1s |
|
54 |
||
55 |
; next |
|
15
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
56 |
rjmp _count_loop |
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
57 |
|
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
58 |
_count_end: |
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
59 |
; done |
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
60 |
ret |
6 | 61 |
|
62 |
;; Blink between dot and empty |
|
63 |
Main_Blink: |
|
64 |
_blink_loop: |
|
65 |
; dot |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
66 |
ldi r16, LED7_DOT |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
67 |
rcall LED7_Show |
6 | 68 |
|
69 |
; wait... |
|
70 |
rcall Delay_1s |
|
71 |
||
72 |
; empty |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
73 |
ldi r16, LED7_EMPTY |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
74 |
rcall LED7_Show |
6 | 75 |
|
76 |
rcall Delay_1s |
|
77 |
||
78 |
; loop |
|
79 |
rjmp _blink_loop |
|
80 |
||
81 |
;; Chase segments |
|
82 |
Main_Spin: |
|
83 |
_spin_init: |
|
84 |
; init from top |
|
85 |
ldi r24, 0b00000001 |
|
86 |
||
87 |
_spin_next: |
|
88 |
; display |
|
89 |
mov r16, r24 |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
90 |
rcall LED7_ShowRaw |
6 | 91 |
|
18 | 92 |
; delay |
93 |
rcall Timer_Sleep_1s |
|
6 | 94 |
|
95 |
; next segment |
|
96 |
lsl r24 |
|
97 |
||
98 |
; go back to A if we hit G |
|
99 |
sbrc r24, 6 |
|
100 |
rjmp _spin_init |
|
101 |
||
102 |
rjmp _spin_next |
|
4 | 103 |
|
104 |
Main: |
|
3 | 105 |
init: |
106 |
; Stack |
|
107 |
ldi r16, high(RAMEND) |
|
108 |
ldi r17, low(RAMEND) |
|
109 |
out SPH, r16 |
|
110 |
out SPL, r17 |
|
111 |
||
112 |
; Enable interrupts |
|
113 |
sei |
|
114 |
||
8 | 115 |
; ADC (slowest to start up) |
15
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
116 |
; rcall ADC_Init |
18 | 117 |
|
118 |
; Timer |
|
119 |
rcall Timer_Init |
|
8 | 120 |
|
3 | 121 |
; SPI |
122 |
rcall SPI_Init |
|
123 |
||
8 | 124 |
; LCD (requires interrupts, blocks) |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
125 |
rcall LED7_Init |
6 | 126 |
|
127 |
; Run |
|
128 |
; spin! |
|
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
129 |
rcall Main_Spin |
15
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
130 |
|
c8f3a514bbef
read SPI to r10, and use it (hack)
Tero Marttila <terom@fixme.fi>
parents:
8
diff
changeset
|
131 |
; count! |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
132 |
; rcall Main_Countdown |
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
16
diff
changeset
|
133 |
; rcall Main_Blink |
4 | 134 |
|
135 |
end: |
|
136 |
rjmp end |
|
137 |