equal
deleted
inserted
replaced
51 ret |
51 ret |
52 |
52 |
53 ;; Send byte |
53 ;; Send byte |
54 ;; Input: r16 |
54 ;; Input: r16 |
55 ;; XXX: should not be busy... |
55 ;; XXX: should not be busy... |
56 SPI_Send: |
56 SPI_SendRecv: |
57 ; Flag |
57 ; Flag |
58 sbi SPI_FLAGS, SPI_BUSY |
58 sbi SPI_FLAGS, SPI_BUSY |
59 |
59 |
60 ; Enable slave (low) |
60 ; Enable slave (low) |
61 cbi SPI_PORT, SPI_SS |
61 cbi SPI_PORT, SPI_SS |
81 ; Store SREG |
81 ; Store SREG |
82 in r16, SREG |
82 in r16, SREG |
83 |
83 |
84 ; Drive SS high (off) |
84 ; Drive SS high (off) |
85 sbi SPI_PORT, SPI_SS |
85 sbi SPI_PORT, SPI_SS |
|
86 |
|
87 ; Read |
|
88 in r10, SPDR |
86 |
89 |
87 ; Flag |
90 ; Flag |
88 cbi SPI_FLAGS, SPI_BUSY |
91 cbi SPI_FLAGS, SPI_BUSY |
89 |
92 |
90 ; Done |
93 ; Done |
139 |
142 |
140 ; empty |
143 ; empty |
141 ldi r16, 0b11111111 |
144 ldi r16, 0b11111111 |
142 |
145 |
143 ; Output |
146 ; Output |
144 rcall SPI_Send |
147 rcall SPI_SendRecv |
145 rcall SPI_Wait |
148 rcall SPI_Wait |
146 |
149 |
147 ; Enable |
150 ; Enable |
148 cbi LCD_PORT, LCD_OE |
151 cbi LCD_PORT, LCD_OE |
149 |
152 |
171 |
174 |
172 ;; Display a raw segment mask |
175 ;; Display a raw segment mask |
173 ;; Input: r16 |
176 ;; Input: r16 |
174 LCD_ShowRaw: |
177 LCD_ShowRaw: |
175 ; Invert |
178 ; Invert |
176 com r16 |
179 ; com r16 |
177 |
180 |
178 ; Display |
181 ; Display |
179 rjmp SPI_Send |
182 rjmp SPI_SendRecv |
180 |
183 |
181 ;; ADC |
184 ;; ADC |
182 .equ ADC_DDR = DDRC |
185 .equ ADC_DDR = DDRC |
183 .equ ADC_PORT = PORTC |
186 .equ ADC_PORT = PORTC |
184 .equ ADC_PIN = PORTC0 |
187 .equ ADC_PIN = PORTC0 |
261 ; Returns once we've hit zero |
264 ; Returns once we've hit zero |
262 Main_Countdown: |
265 Main_Countdown: |
263 ; init from 9 |
266 ; init from 9 |
264 ldi r24, LCD_9 |
267 ldi r24, LCD_9 |
265 |
268 |
266 loop: |
269 _count_loop: |
267 ; display |
270 ; display |
268 mov r16, r24 |
271 mov r16, r24 |
269 rcall LCD_Show |
272 rcall LCD_Show |
270 |
273 |
271 ; exit if zero |
274 ; exit if zero |
272 tst r24 |
275 tst r24 |
273 ret |
276 breq _count_end |
274 |
277 |
275 ; count down |
278 ; count down |
276 dec r24 |
279 dec r24 |
277 |
280 |
278 ; wait... |
281 ; wait... |
279 rcall Delay_1s |
282 rcall Delay_1s |
280 |
283 |
281 ; next |
284 ; next |
282 rjmp loop |
285 rjmp _count_loop |
|
286 |
|
287 _count_end: |
|
288 ; done |
|
289 ret |
283 |
290 |
284 ;; Blink between dot and empty |
291 ;; Blink between dot and empty |
285 Main_Blink: |
292 Main_Blink: |
286 _blink_loop: |
293 _blink_loop: |
287 ; dot |
294 ; dot |
310 ; display |
317 ; display |
311 mov r16, r24 |
318 mov r16, r24 |
312 rcall LCD_ShowRaw |
319 rcall LCD_ShowRaw |
313 |
320 |
314 ; variable delay -> r16 |
321 ; variable delay -> r16 |
315 rcall ADC_Read8 |
322 ;rcall ADC_Read8 |
|
323 ;mov r20, r16 |
|
324 |
|
325 ; delay from input |
|
326 mov r20, r10 |
|
327 |
|
328 ; constant |
|
329 ;ldi r20, 20 |
316 |
330 |
317 ; short delay, from ADC |
331 ; short delay, from ADC |
318 mov r20, r16 |
332 ldi r21, 255 |
319 ldi r21, 1 |
|
320 rcall ShortDelay |
333 rcall ShortDelay |
321 |
334 |
322 ; next segment |
335 ; next segment |
323 lsl r24 |
336 lsl r24 |
324 |
337 |
338 |
351 |
339 ; Enable interrupts |
352 ; Enable interrupts |
340 sei |
353 sei |
341 |
354 |
342 ; ADC (slowest to start up) |
355 ; ADC (slowest to start up) |
343 rcall ADC_Init |
356 ; rcall ADC_Init |
344 |
357 |
345 ; SPI |
358 ; SPI |
346 rcall SPI_Init |
359 rcall SPI_Init |
347 |
360 |
348 ; LCD (requires interrupts, blocks) |
361 ; LCD (requires interrupts, blocks) |
349 rcall LCD_Init |
362 rcall LCD_Init |
350 |
363 |
351 ; Run |
364 ; Run |
352 ; spin! |
365 ; spin! |
353 rcall Main_Spin |
366 rcall Main_Spin |
|
367 |
|
368 ; count! |
|
369 ; rcall Main_Countdown |
|
370 ; rcall Main_Blink |
354 |
371 |
355 end: |
372 end: |
356 rjmp end |
373 rjmp end |
357 |
374 |