reti
; T1 CAPT1
-rjmp T1_CAPTURE
+reti
; T1 COMP A
reti
; T1 OVF1
-reti
+rjmp T1_OVERFLOW
; T0 OVF0
reti
reti
; ANA COMP
-reti
+rjmp ANA_COMP
; PCINT
reti
; uart init
UART_INIT:
- ldi r16,51 ; 9600 bps @ 8mhz
+ ldi r16,51 ; 9k6 bps @ 8mhz
out UBRRL, r16
out UBRRH, r0
- ldi r16,(1<<UCSZ0)|(1<<UCSZ1) ; 8 data bits, no parity, 1 stop bit
+ ldi r16,(1<<UCSZ0)|(1<<UCSZ1) ; 8n1
out UCSRC,r16;
sbi UCSRB,TXEN ; enable tx
; timer init
- TIME_INIT:
+ TIMER_INIT:
- ldi r16,(1<<CS10)|(1<<CS11) ; prescaler 1/64
+ ; prescaler 64
+ ldi r16,(1<<CS10)|(1<<CS11)
out TCCR1B,r16
- ldi r16,(1<<ICIE1) ; enable input capture interrupt
- out TIMSK,r16
-
; analog comparator init
ANA_COMP_INIT:
- ; interrupt if voltage is higher, enable input capture function ot tc1
- ldi r16,(1<<ACIS0)|(1<<ACIS0)|(1<<ACIC) ; (no analog comp interrupt!)
+ ; interrupt if voltage is higher
+ ; enable input capture function ot tc1
+ ldi r16,(1<<ACIS0)|(1<<ACIS1)
out ACSR,r16
; output for rc element
- ldi r17,(1<<DDB2)
- out DDRB,r17
- out PORTB,r0
+ RC_PIN_INIT:
+ sbi DDRD,DDD2 ; pin 2 port d is output
- sei ; global interrupt enable
MAIN:
+
+ ; print 'S'tart symbol via uart
+ ldi r17,0x53
+ sbis UCSRA,UDRE
rjmp MAIN
+ out UDR,r17
+
+ ; decharge rc pin
+ cbi PORTD,PORTD2
+
+ ; reset timer counter 1 and enable overflow interrupt
+ out TCNT1H,r0
+ out TCNT1L,r0
+ ldi r17,(1<<TOIE1)
+ out TIMSK,r17
+
+ ; global interrupt enable
+ sei
+
+ ; 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
;
-; timer 1 input capture interrupt routine
+; analog comparator interrupt routine
;
-T1_CAPTURE:
+ANA_COMP:
- ; disable input capture interrupt
- in r17,TIMSK
- cbr r17,ICIE1
- out TIMSK,r17
-
- ; pull low the rc element
- cbi PORTB,PORTB2
+ ; immediately disable the analog comparator interrupt
+ cbi ACSR,ACIE
; read the captured value
- in r19,ICR1L
- in r18,ICR1H
+ 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
rjmp LOOP_TWO
out UDR,r19
+ ; reset timer counter
+ out TCNT1H,r0
+ out TCNT1L,r0
+
; enable timer 1 overflow interrupt
in r17,TIMSK
sbr r17,TOIE1
T1_OVERFLOW:
- ; disable timer 1 overflow interrupt
- in r17,TOIE1
- cbr r17,TOIE1
+ ; immediately disable timer 1 overflow interrupt
+ in r17,TIMSK
+ cbr r17,(1<<TOIE1)
out TIMSK,r17
- ; uart space out
- ldi r17,0x20
- LOOP_THREE:
+ ; uart debug out
+ ldi r17,0x4f
+ OVF_SEND:
sbis UCSRA,UDRE
- rjmp LOOP_TWO
+ rjmp OVF_SEND
out UDR,r17
; reset timer counter
out TCNT1H,r0
out TCNT1L,r0
- ; pull rc element high
- sbi PORTB,PORTB2
+ ; enable analog comparator interrupt
+ sbi ACSR,ACIE
- ; enable input capture interrupt
- in r17,TIMSK
- sbr r17,ICIE1
- out TIMSK,r17
+ ; pull rc element high
+ sbi PORTD,PORTD2
reti