1 ;; vim: set ft=avr: |
|
2 |
|
3 .nolist |
|
4 .include "m168def.inc" ; Same family as 328P |
|
5 .list |
|
6 |
|
7 |
|
8 ;; Interrupt Vector |
|
9 .org 0x00 |
|
10 rjmp init |
|
11 |
|
12 .org OC1Aaddr |
|
13 ; Timer/Counter1 Compare Output A |
|
14 rjmp Timer_OC1A |
|
15 |
|
16 .org OC0Aaddr |
|
17 ; Timer/Counter0 Compare Output A |
|
18 rjmp Timer_OC0A |
|
19 |
|
20 .org SPIaddr |
|
21 rjmp SPI_Interrupt |
|
22 |
|
23 |
|
24 cseg0: .org 0x40 |
|
25 |
|
26 ;; Syntax |
|
27 .include "macros.inc" |
|
28 |
|
29 ;; SPI |
|
30 .include "spi.inc" |
|
31 |
|
32 ;; Matrix |
|
33 .include "matrix.inc" |
|
34 |
|
35 ;; Timer |
|
36 .set TIMER0_CB_A = Matrix_ScanCol |
|
37 |
|
38 .include "timer.inc" |
|
39 |
|
40 ;; Utils |
|
41 .include "delay.inc" |
|
42 |
|
43 ;; Font rendering |
|
44 .include "font.inc" |
|
45 |
|
46 ;; Scan through each pixel |
|
47 Main_ScanRaw: |
|
48 ; init |
|
49 ldi r18, 1 |
|
50 ldi r19, 1 |
|
51 |
|
52 scan_loop: |
|
53 ; write out to SPI |
|
54 sts spi_outbuf + 0, r18 ; rows |
|
55 sts spi_outbuf + 1, r19 ; columns |
|
56 |
|
57 rcall SPI_SendRecv |
|
58 |
|
59 ; delay |
|
60 ldi r20, 5 ; ~4M cycles |
|
61 rcall VarDelay |
|
62 |
|
63 ; cols |
|
64 lsl r19 ; next col |
|
65 brcc scan_loop ; refresh if we didn't overflow |
|
66 |
|
67 rol r19 ; shift back from C into r21.0 |
|
68 |
|
69 ; rows |
|
70 lsl r18 ; next row |
|
71 brcc scan_loop ; refresh if we didn't overflow |
|
72 |
|
73 rol r18 ; shift back from C into r20.0 |
|
74 |
|
75 ; one scan completed |
|
76 ret |
|
77 |
|
78 ;; Scan with test pattern |
|
79 Main_ScanTest: |
|
80 ; Generate pattern |
|
81 ; end of buffer |
|
82 ldi r17, MATRIX_BUF_COLS |
|
83 ldi XL, low(matrix_colbuf + MATRIX_BUF_COLS) |
|
84 ldi XH, high(matrix_colbuf + MATRIX_BUF_COLS) |
|
85 |
|
86 ; bit pattern |
|
87 ldi r16, 0b11 |
|
88 |
|
89 st_loop: |
|
90 ; put, pre-decrement |
|
91 st -X, r16 |
|
92 |
|
93 ; flip |
|
94 rol r16 |
|
95 |
|
96 ; loop until zero |
|
97 dec r17 |
|
98 brne st_loop |
|
99 |
|
100 st_animate: |
|
101 ; Animate |
|
102 ; shift right |
|
103 rcall Matrix_ShiftLeft |
|
104 |
|
105 ; wait for X/16th of a second |
|
106 ldi XH, high(8 * 1024) |
|
107 ldi XL, low(8 * 1024) |
|
108 |
|
109 rcall Timer_Sleep |
|
110 |
|
111 ; loop |
|
112 rjmp st_animate |
|
113 |
|
114 |
|
115 ;; Display device code memory |
|
116 Main_ScanCode: |
|
117 ; Code start |
|
118 ldi ZL, low(cseg0 * 2) ; word addr |
|
119 ldi ZH, high(cseg0 * 2) ; word addr |
|
120 |
|
121 ; Pause refresh |
|
122 cli |
|
123 |
|
124 ; Load initial frame |
|
125 ; to first frame, starting from right edge |
|
126 ldi r17, 8 |
|
127 ldi XL, low(matrix_colbuf + 16) |
|
128 ldi XH, high(matrix_colbuf + 16) |
|
129 |
|
130 sc_load_initial: |
|
131 ; one byte |
|
132 lpm r16, Z+ |
|
133 st -X, r16 |
|
134 |
|
135 ; loop until zero |
|
136 dec r17 |
|
137 brne sc_load_initial |
|
138 |
|
139 ; the first ShiftLeft below will jump to the end of the framebuffer |
|
140 |
|
141 sc_next: |
|
142 ; Show this frame |
|
143 rcall Matrix_ShiftLeft |
|
144 |
|
145 ; Load next frame |
|
146 ldi r17, 8 |
|
147 ldi XL, low(matrix_colbuf + 8) |
|
148 ldi XH, high(matrix_colbuf + 8) |
|
149 |
|
150 sc_load_next: |
|
151 ; one byte |
|
152 lpm r16, Z+ |
|
153 st -X, r16 |
|
154 |
|
155 ; loop until zero |
|
156 dec r17 |
|
157 brne sc_load_next |
|
158 |
|
159 ; Enable refresh |
|
160 sei |
|
161 |
|
162 ; Animate from this -> next frame |
|
163 ldi r17, 8 ; 8 columns |
|
164 |
|
165 sc_anim: |
|
166 ; wait for X/16th of a second |
|
167 ldi XH, high(2 * 1024) |
|
168 ldi XL, low(2 * 1024) |
|
169 |
|
170 rcall Timer_Sleep |
|
171 |
|
172 ; shift |
|
173 rcall Matrix_ShiftLeft |
|
174 |
|
175 ; loop until zero |
|
176 dec r17 |
|
177 brne sc_anim |
|
178 |
|
179 ; Pause refresh |
|
180 cli |
|
181 |
|
182 ; Move next -> this |
|
183 ldi r17, 8 |
|
184 ldi XL, low(matrix_colbuf + 16) |
|
185 ldi XH, high(matrix_colbuf + 16) |
|
186 ldi YL, low(matrix_colbuf + 8) |
|
187 ldi YH, high(matrix_colbuf + 8) |
|
188 |
|
189 sc_move_this: |
|
190 ; one byte |
|
191 ld r16, -Y |
|
192 st -X, r16 |
|
193 |
|
194 ; loop until zero |
|
195 dec r17 |
|
196 brne sc_move_this |
|
197 |
|
198 sbi PIND, PIND7 |
|
199 |
|
200 ; Load next frame, and animate |
|
201 rjmp sc_next |
|
202 |
|
203 Main_ScanText: |
|
204 |
|
205 ; Constants |
|
206 stxt_message: ; text to render |
|
207 .db 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x0 ; 'hello world!' |
|
208 |
|
209 ; Load into buffer |
|
210 ldi ZL, low(stxt_message * 2) |
|
211 ldi ZH, high(stxt_message * 2) |
|
212 |
|
213 rcall Text_LoadString |
|
214 |
|
215 sbi PORTD, PIND7 |
|
216 |
|
217 ; Display |
|
218 rcall Text_ShowString |
|
219 |
|
220 ; Done |
|
221 ret |
|
222 |
|
223 Main: |
|
224 init: |
|
225 ; Stack |
|
226 ldi r16, high(RAMEND) |
|
227 ldi r17, low(RAMEND) |
|
228 out SPH, r16 |
|
229 out SPL, r17 |
|
230 |
|
231 ; Enable interrupts |
|
232 sei |
|
233 |
|
234 ; DEBUG |
|
235 sbi DDRD, PORTD7 |
|
236 cbi PORTD, PORTD7 |
|
237 |
|
238 ; Timer |
|
239 rcall Timer_Init |
|
240 |
|
241 ; SPI |
|
242 rcall SPI_Init |
|
243 |
|
244 ; Matrix |
|
245 rcall Matrix_Init |
|
246 |
|
247 ; Run |
|
248 ; rcall Main_ScanRaw |
|
249 ; rcall Main_ScanTest |
|
250 ; rcall Main_ScanCode |
|
251 rcall Main_ScanText |
|
252 |
|
253 end: |
|
254 rjmp end |
|
255 |
|