ldi tmp,low(RAMEND)
out SPL,tmp
-; enable interrupts int0,int1
+; enable interrupts int0,int1,sleep
ldi tmp,((1<<INT0)|(1<<INT1))
out GIMSK,tmp
; int0/1 setup
-ldi tmp,((1<<ISC01)|(0<<ISC00)|(1<<ISC11)|(0<<ISC10))
+ldi tmp,((1<<ISC01)|(0<<ISC00)|(1<<ISC11)|(0<<ISC10)|(1<<SE))
out MCUCR,tmp
; enable t/c overflow interrupt and icp
ldi tmp,baudrate
out UBRR,tmp
sbi UCR,TXEN
+; debug
+.ifdef DEBUG
+ldi tmp,0x49
+out UDR,tmp
+.endif
; enable pullups on int0, int1, clk, icp io ports
ldi tmp,((1<<PD2)|(1<<PD3)|(1<<PD5)|(1<<PD6))
MAIN:
-; loop and wait for interrupts
+; debug
+.ifdef DEBUG
+ldi tmp,0x4d
+out UDR,tmp
+.endif
+
+; sleep/wait for next interrupt
+sleep
+
+; go to sleep again
rjmp MAIN
; ----------------
REC_CARD:
+.ifdef DEBUG
+ldi tmp,0x52
+out UDR,tmp
+.endif
+
; input & pullup
cbi DDRD,DDD6
sbi PORTD,PD6
CALC_DELTA_CLOCK:
+.ifdef DEBUG
+ldi tmp,0x63
+out UDR,tmp
+.endif
+
; store counters
mov counter_l_tmp,counter_l
mov counter_h_tmp,counter_h
TOGGLE_ICP_SENSE:
+.ifdef DEBUG
+ldi tmp,0x54
+out UDR,tmp
+.endif
+
; toggle according to state
in tmp,TCCR1B
cbr tmp,ICES1
FWD_TO_CAM:
+.ifdef DEBUG
+ldi tmp,0x66
+out UDR,tmp
+.endif
+
; activate led
sbi PORTB,LED_FWD_TO_CARD
cbi PORTB,LED_FWD_TO_CAM
PREPARE_UART:
+.ifdef DEBUG
+ldi tmp,0x50
+out UDR,tmp
+.endif
+
; write transfer data to sram
ldi ZL,0x60
st Z+,counter_l
REC_CAM:
+.ifdef DEBUG
+ldi tmp,0x72
+out UDR,tmp
+.endif
+
; first thing - pullup on
cbi DDRD,DDD3
sbi DDRD,PD3
TOGGLE_INT_SENSE:
+.ifdef DEBUG
+ldi tmp,0x73
+out UDR,tmp
+.endif
+
in tmp,MCUCR
cbr tmp,ISC10
sbrs state,HIGH_F
FWD_TO_CARD:
+.ifdef DEBUG
+ldi tmp,0x46
+out UDR,tmp
+.endif
+
; activate led
sbi PORTB,LED_FWD_TO_CAM
cbi PORTB,LED_FWD_TO_CARD
T1_OVERFLOW:
+.ifdef DEBUG
+ldi tmp,0x74
+out UDR,tmp
+.endif
+
; increment counter overflow
add overflow_counter,one
RST_CAM:
+.ifdef DEBUG
+ldi tmp,0x69
+out UDR,tmp
+.endif
+
; by now just jump to init
rjmp INIT