.nolist
.include "m168def.inc" ; Same family as 328P
.list
;; Interrupt Vector
.org 0x00
rjmp init
.org OC1Aaddr
; Timer/Counter1 Overflow
rjmp Timer_OC1A
.org SPIaddr
rjmp SPI_Interrupt
.org ADCCaddr
rjmp ADC_Interrupt
.org 0x40
;; Syntax
.include "macros.inc"
;; SPI
.include "spi.inc"
;; LCD
.include "led7seg.inc"
;; ADC
.include "adc.inc"
;; Timer
.include "timer.inc"
;; Utils
.include "delay.inc"
;; Count down from 9
; Returns once we've hit zero
Main_Countdown:
; init from F
ldi r24, LED7_F
_count_loop:
; display
mov r16, r24
rcall LED7_Show
; exit if zero
tst r24
breq _count_end
; count down
dec r24
; wait...
rcall Delay_1s
; next
rjmp _count_loop
_count_end:
; done
ret
;; Blink between dot and empty
Main_Blink:
_blink_loop:
; dot
ldi r16, LED7_DOT
rcall LED7_Show
; wait...
rcall Delay_1s
; empty
ldi r16, LED7_EMPTY
rcall LED7_Show
rcall Delay_1s
; loop
rjmp _blink_loop
;; Chase segments
Main_Spin:
_spin_init:
; init from top
ldi r24, 0b00000001
_spin_next:
; display
mov r16, r24
mov r17, r24
com r17
rcall LED7_ShowRaw
; delay
rcall ADC_Read8
;mov r16, r10
ldi r17, 64
mul r16, r17
mov XL, r0
mov XH, r1
rcall Timer_Sleep
; next segment
lsl r24
; go back to A if we hit G
sbrc r24, 6
rjmp _spin_init
rjmp _spin_next
Main:
init:
; DEBUG
sbi DDRD, PORTD7
sbi PORTD, PORTD7
; Stack
ldi r16, high(RAMEND)
ldi r17, low(RAMEND)
out SPH, r16
out SPL, r17
; Enable interrupts
sei
; ADC (slowest to start up)
rcall ADC_Init
; Timer
rcall Timer_Init
; SPI
rcall SPI_Init
; LCD (requires interrupts, blocks)
rcall LED7_Init
; Run
; spin!
rcall Main_Spin
; count!
; rcall Main_Countdown
; rcall Main_Blink
end:
rjmp end