.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 1 compare a
-nop
-reti
-
-; timer 1 compare b
-nop
-reti
-
-; 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/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 r25,0
-ldi r30,0
-ldi r31,(1<<PINC0)
-
-MAIN:
-in r25,ADCH
-cp r23,r25
-breq LASER_ON
-rjmp MAIN
-
-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
+ldi r30,0x00 ; light status
+ldi r28,1 ; constants
+ldi r27,0x01;
+out DDRC,r27 ; select pin 0 as output
+rjmp LIGHT
+
+LIGHT:
+cpi r30,0x00
+breq LIGHT_ON
+rjmp LIGHT_OFF
+
+LIGHT_ON:
+ldi r31,0 ; reset wait counter
+ldi r30,0x01
out PORTC,r30
-rjmp MAIN
-
-INC_COUNT:
-inc r23
-reti
+rjmp WAIT
+LIGHT_OFF:
+ldi r31,0
+ldi r30,0x00
+out PORTC,r30
+rjmp WAIT
+
+WAIT:
+ldi r29,0 ; reset inner wait counter
+add r31,r28 ; increment wait counter
+cpi r31,0xff ; after 255 steps
+breq LIGHT
+rjmp WAIT_MORE
+
+WAIT_MORE:
+ldi r25,0 ; reset inner inner wait counter
+add r29,r28 ; increment inner wait loop counter
+cpi r29,0xff ; goto first wait loop after 255 cycles
+breq WAIT
+rjmp WAIT_MORE_MORE
+
+WAIT_MORE_MORE:
+add r25,r28 ; inc inner inner wait counter
+cpi r25,0x05 ; goto wait_more loop
+breq WAIT_MORE
+rjmp WAIT_MORE_MORE