final version (before xmas)
authorhackbard <hackbard@hackdaworld.org>
Sun, 18 Dec 2011 21:31:53 +0000 (22:31 +0100)
committerhackbard <hackbard@hackdaworld.org>
Sun, 18 Dec 2011 21:31:53 +0000 (22:31 +0100)
beginners/rgb_moritz.asm

index 51e4c32..bc3a72a 100644 (file)
@@ -7,20 +7,27 @@
 ; author: hackbard@hackdaworld.org
 
 
-.include "../include/2313def.inc"
+.include "../include/tn2313def.inc"
 
 ; defines & equals
 .def zero = r0
 .def one = r1
+.def two = r2
 .def tmp = r16
 .def count = r17
 .def red = r18
 .def green = r19
 .def blue = r20
 .def rgb_level = r21
+.def rgb_dir = r22
+.def rgb_upd_cnt = r23
 .equ pin_red = 0x01
 .equ pin_green = 0x02
 .equ pin_blue = 0x04
+.equ max = 255
+.equ min = 0
+.equ mid = 170
+.equ rgb_upd = 10
 
 ; interrupt vectors
 ; reset
@@ -34,9 +41,9 @@ reti
 ; timer/counter compare
 reti
 ; timer/counter overflow 1
-rjmp TCO1
-; timer/counter overflow 0
 reti
+; timer/counter overflow 0
+rjmp TCO0
 ; uart rx complete
 reti
 ; uart data register empty
@@ -57,18 +64,20 @@ ldi tmp,low(RAMEND)
 out SPL,tmp
 
 ; timer: clock/8
-ldi tmp,(1<<CS11)
-out TCCR1B,tmp
+ldi tmp,(1<<CS00)
+out TCCR0B,tmp
 
 ; enable timer overflow interrupt
-ldi tmp,(1<<TOIE1)
+ldi tmp,(1<<TOIE0)
 out TIMSK,tmp
 
 ; register values
-ldi tmp,1
-mov one,tmp
 ldi tmp,0
 mov zero,tmp
+ldi tmp,1
+mov one,tmp
+ldi tmp,2
+mov two,tmp
 
 ; port b 0-2 -> output
 ; port b 0-2 -> high
@@ -76,22 +85,40 @@ ldi tmp,0x07
 out DDRB,tmp
 out PORTB,tmp
 
+; uart
+ldi tmp,0
+out UBRRH,tmp
+ldi tmp,25
+out UBRRL,tmp
+ldi tmp,(1<<TXEN)
+out UCSRB,tmp
+ldi tmp,(1<<UCSZ0)|(1<<UCSZ1)
+out UCSRC,tmp
+
 ;
 ; more init
 ;
 
 ; rgb offsets
-mov red,zero
-ldi tmp,85
+ldi tmp,min
+mov red,tmp
+ldi tmp,mid
 mov green,tmp
-ldi tmp,170
+ldi tmp,mid
 mov blue,tmp
 
+; rgb propagation init
+ldi rgb_dir,0x04
+
 ; level init
 ldi rgb_level,0x07
 
 ; init count variable
 mov count,zero
+mov rgb_upd_cnt,zero
+
+; enable interrupts
+sei
 
 ;
 ; main routine
@@ -101,12 +128,65 @@ MAIN:
 
 rjmp MAIN
 
-TCO1:
+TCO0:
 
 cp count,zero
 brne CHECK_RED
+
+; update rgb propagation
+
+cpi rgb_upd_cnt,rgb_upd
+brne POWER_LEDS
+
+; reset counter
+mov rgb_upd_cnt,zero
+
+UPD_R_L:
+cpi red,min
+brne UPD_R_H
+andi rgb_dir,~0x01
+UPD_R_H:
+cpi red,max
+brne UPD_G_L
+ori rgb_dir,0x01
+
+UPD_G_L:
+cpi green,min
+brne UPD_G_H
+andi rgb_dir,~0x02
+UPD_G_H:
+cpi green,max
+brne UPD_B_L
+ori rgb_dir,0x02
+
+UPD_B_L:
+cpi blue,min
+brne UPD_B_H
+andi rgb_dir,~0x04
+UPD_B_H:
+cpi blue,max
+brne INC_RGB
+ori rgb_dir,0x04
+
+; inc rgb values
+INC_RGB:
+sbrc rgb_dir,0
+sub red,two
+add red,one
+sbrc rgb_dir,1
+sub green,two
+add green,one
+sbrc rgb_dir,2
+sub blue,two
+add blue,one
+
+; power on the leds
+POWER_LEDS:
 mov rgb_level,zero
 
+; increase rgp update counter
+add rgb_upd_cnt,one
+
 CHECK_RED:
 
 cp count,red
@@ -129,5 +209,8 @@ SET_PORTS:
 
 out PORTB,rgb_level
 
+; increase counter
+add count,one
+
 reti