MAIN:
- ; print 'S'tart symbol via uart
- ldi r17,0x53
- sbis UCSRA,UDRE
- rjmp MAIN
- out UDR,r17
+ ; status register
+ ldi r31,0
; decharge rc pin
cbi PORTD,PORTD2
- ; reset timer counter 1 and enable overflow interrupt
- out TCNT1H,r0
- out TCNT1L,r0
+ ; enable overflow interrupt
ldi r17,(1<<TOIE1)
out TIMSK,r17
; loop forever
MAIN_LOOP:
- ldi r21,0
- WLOOP1:
- ldi r22,0
- WLOOP2:
- inc r22
- cpi r22,0xff
- brne WLOOP2
- inc r21
- cpi r21,0xff
- brne WLOOP1
-
- ; tell the world
-
- ; separate with a space
- ldi r17,0x20
- SPACE1:
- sbis UCSRA,UDRE
- rjmp SPACE1
- out UDR,r17
-
- ; aco status
- ldi r17,0x30
- sbic ACSR,ACO
- ldi r17,0x31
- ACO_STAT:
- sbis UCSRA,UDRE
- rjmp ACO_STAT
- out UDR,r17
-
- ; aci status
- ldi r17,0x30
- sbic ACSR,ACIE
- ldi r17,0x31
- ACI_STAT:
- sbis UCSRA,UDRE
- rjmp ACI_STAT
- out UDR,r17
-
- ; pin status
- ldi r17,0x30
- sbic PORTD,PORTD2
- ldi r17,0x31
- PIN_STAT:
- sbis UCSRA,UDRE
- rjmp PIN_STAT
- out UDR,r17
-
- ; ti status
- ldi r17,0x30
- in r23,TIMSK
- sbrc r23,TOIE1
- ldi r17,0x31
- TI_STAT:
- sbis UCSRA,UDRE
- rjmp TI_STAT
- out UDR,r17
-
- ; a space again for separation
- ldi r17,0x20
- SPACE2:
- sbis UCSRA,UDRE
- rjmp SPACE2
- out UDR,r17
-
- ; loop
- rjmp MAIN_LOOP
+ ; loop
+ rjmp MAIN_LOOP
;
; analog comparator interrupt routine
ANA_COMP:
- ; immediately disable the analog comparator interrupt
+ ; immediately take away the clock
+ out TCCR1B,r0
+
+ ; disable comparator + del possible interrupt flag
cbi ACSR,ACIE
+ ; pull low the rc element
+ cbi PORTD,PORTD2
+
; read the captured value
in r19,TCNT1L
in r18,TCNT1H
- ; pull low the rc element
- cbi PORTD,PORTD2
-
- ; uart out
- ANA_COMP_SEND:
- ldi r17,0x61
- sbis UCSRA,UDRE
- rjmp ANA_COMP_SEND
- out UDR,r17
LOOP_ONE:
sbis UCSRA,UDRE
rjmp LOOP_ONE
out TCNT1H,r0
out TCNT1L,r0
- ; enable timer 1 overflow interrupt
- in r17,TIMSK
- sbr r17,TOIE1
- out TIMSK,r17
+ ; clear possible overflow flag
+ ldi r17,(1<<TOV1)
+ out TIFR,r17
+
+ ; enable the counter
+ ldi r17,(1<<CS10)|(1<<CS11)
+ out TCCR1B,r17
reti
T1_OVERFLOW:
- ; immediately disable timer 1 overflow interrupt
- in r17,TIMSK
- cbr r17,(1<<TOIE1)
- out TIMSK,r17
+ ; check whether second run
+ cpi r31,4
+ brne MARK_2ND_RUN
- ; uart debug out
- ldi r17,0x4f
- OVF_SEND:
- sbis UCSRA,UDRE
- rjmp OVF_SEND
- out UDR,r17
+ ; reset to a first run
+ ldi r31,0
- ; reset timer counter
- out TCNT1H,r0
- out TCNT1L,r0
-
- ; enable analog comparator interrupt
+ ; enable analog comparator interrupt + del possible interrupt flags
sbi ACSR,ACIE
+ sbi ACSR,ACI
; pull rc element high
sbi PORTD,PORTD2
reti
+ MARK_2ND_RUN:
+ inc r31
+ reti
+