; author: hackbard@hackdaworld.org
;
-.include "../include/2313def.inc"
+.include "../include/m163def.inc"
; ------------------
; interrupt vectors:
; ------------------
+
; reset
+nop
rjmp INIT
+
; int0
+nop
reti
+
; int1
+nop
+reti
+
+; timer 2 compare
+nop
+reti
+
+; timer 2 overflow
+nop
+reti
+
+; timer 1 capture
+nop
reti
-; timer/counter capt 1
+
+; timer 1 compare a
+nop
reti
-; timer/counter compare
+
+; timer 1 compare b
+nop
reti
-; timer/counter overflow 1
-rjmp INC_LASER_COUNT
-; timer/counter overflow 0
+
+; timer 1 overflow
+nop
+rjmp LASER_OFF
+
+; timer 0 overflow
+nop
+rjmp INC_COUNT
+
+; spi transfer complete
+nop
reti
+
; uart rx complete
+nop
reti
+
; uart data register empty
+nop
reti
+
; uart tx complete
+nop
+reti
+
+; adc complete
+nop
+reti
+
+; eeprom ready
+nop
reti
+
; analog comparator
+nop
+reti
+
+; twi
+nop
reti
+; -----
+; code:
+; -----
+
INIT:
; set stackpointer
ldi r16,low(RAMEND)
out SPL,r16
-; timer 0 setting
-ldi r16, 3
-out TCCR1B, r16
-; timer 0 enable
-ldi r16, (1<<TOIE1)
-out TIMSK, r16
+; timer/counter 0 setting (f_clk/1024)
+ldi r16,(1<<CS02)|(1<<CS00)
+out TCCR0,r16
+; timer/counter 0 enable
+ldi r16,(1<<TOIE0)
+out TIMSK,r16
+; timer counter 1 setting (f_clk/8)
+ldi r16,(1<<CS11)
+out TCCR1B,r16
+; adc
+ldi r16,(1<<ADLAR) ; left adjusted, pin 0 connected to adc, a ref connected
+out ADMUX,r16
+ldi r16,(1<<ADEN)|(1<<ADSC)|(1<<ADFR) ; enable, running mode, start first conv.
+out ADCSR,r16
+; port c setings
+ldi r16,(1<<DDC0)
+out DDRC,r16
; registers
ldi r23,0
-ldi r24,0
+ldi r25,0
+ldi r30,0
+ldi r31,(1<<PINC0)
MAIN:
-rcall SET_FREQ ; read/set frequency from adc
-
+in r25,ADCH
+cp r23,r25
+breq LASER_ON
rjmp MAIN
-SET_FREQ:
+LASER_ON:
+ldi r16,(1<<TOIE1)|(1<<TOIE0)
+out TIMSK,r16
+out PORTC,r31
+rjmp MAIN
+LASER_OFF:
+ldi r16,(1<<TOIE0)
+out TIMSK,r16
+out PORTC,r30
+rjmp MAIN
-INC_LASER_COUNT:
+INC_COUNT:
inc r23
reti
-TOGGLE_LASER:
-inc r24
-reti
-
-