.def tmp = r16
.def uart_count = r17
.def count = r18
-.def R = r19
-.def G = r20
-.def B = r21
-.def mode r22
-.equ cm 0
-.equ rgb 1
+.def RED = r19
+.def GREEN = r20
+.def BLUE = r21
+.def mode = r22
+.equ cm = 0
+.equ rgb = 1
.def OUTR = r23
.def FULLR = r24
-.equ LED_R PD2
-.equ LED_G PD3
-.equ LED_B PD4
-.equ LED_PORT PORTD
+.equ LED_R = PD2
+.equ LED_G = PD3
+.equ LED_B = PD4
+.equ LED_PORT = PORTD
;
; interrupt voctors
; timer/counter compare
reti
; timer/counter overflow 1
-reti
+rjmp INC_RGB
; timer/counter overflow 0
reti
; uart rx complete
; alloc stack pointer
ldi r16,low(RAMEND)
out SPL,r16
+; timer: clock/1024
+ldi tmp,((1<<CS11))
+out TCCR1B,tmp
+; enable timer overflow interrupt
+ldi tmp,(1<<TOIE1)
+out TIMSK,tmp
; enable uart + rx complete interrupt
ldi tmp,51 ; 9600 baud, 0,2% error @ 8mhz
out UBRR,tmp
mov zero,tmp
ldi uart_count,0
ldi count,0
-ldi R,0xff
-ldi G,0xff
-ldi B,0xff
+ldi RED,0x22
+ldi GREEN,0x77
+ldi BLUE,0xff
; led pins are outputs
ldi tmp,((1<<LED_R)|(1<<LED_G)|(1<<LED_B))
out DDRD,tmp
-; enable interrupts (global=
+; enable interrupts (global)
sei
; jump to main
rjmp MAIN
+;
+; increase rgb values
+;
+INC_RGB:
+add RED,one
+add BLUE,one
+add GREEN,one
+reti
+
;
; main routine
;
;
; reset leds
;
+RESET_LEDS:
ldi OUTR,((1<<LED_R)|(1<<LED_G)|(LED_B))
-add count,one
-ret
+rjmp CHECK_RED
;
; check red + jump to green check
;
CHECK_RED:
-cp count,R
+cp count,RED
breq SWITCH_OFF_R
rjmp CHECK_GREEN
; check green + jump to blue check
;
CHECK_GREEN:
-cp count,G
+cp count,GREEN
breq SWITCH_OFF_G
rjmp CHECK_BLUE
; check blue + "do the light"
;
CHECK_BLUE:
-cp count,B
+cp count,BLUE
breq SWITCH_OFF_B
rjmp LIGHT
;
; switch of blue led
;
-SWITCH_OFF_G:
-sub OUTR,(1<<LED_B)
+SWITCH_OFF_B:
+subi OUTR,(1<<LED_B)
rjmp LIGHT
;
;
LIGHT:
ldi FULLR,0xff
-sub FULLR,OUTR
+eor FULLR,OUTR
out LED_PORT,FULLR
-
rjmp INC_COUNT
;
; increase counter + jump back to main loop
;
-add counter,one
+INC_COUNT:
+add count,one
rjmp LOOP
;