corrected careless mistake
[my-code/atmel.git] / beginners / rgb_mali.asm
index 3b9815d..8b26baf 100644 (file)
@@ -83,7 +83,7 @@ out TIMSK,tmp
 ; enable uart + rx complete interrupt
 ldi tmp,51 ; 9600 baud, 0,2% error @ 8mhz
 out UBRR,tmp
-ldi tmp,((1<<RXCIE)|(1<<RXEN))
+ldi tmp,((1<<RXCIE)|(1<<RXEN)|(1<<TXEN))
 out UCR,tmp
 ; init registers
 ldi tmp,1
@@ -93,7 +93,7 @@ mov zero,tmp
 mov countrgb,tmp
 ldi uart_count,0
 ldi count,0
-ldi RED,CM1
+ldi RED,CM2
 ldi GREEN,0x0
 ldi BLUE,0x0
 ; led pins are outputs
@@ -114,6 +114,11 @@ cpi mode,cm
 breq CM_ACTION
 reti
 
+;
+; specify action
+;
+
+
 ;
 ; continuous mode action
 ;
@@ -135,7 +140,7 @@ rjmp MAKE_RGB
 ; reset rgb
 ;
 RESET_RGB:
-ldi RED,CM1
+ldi RED,CM2
 mov GREEN,zero
 mov BLUE,zero
 mov desc,zero
@@ -163,11 +168,13 @@ rjmp MAKE_RGB
 MAKE_RGB:
 ldi tmp,(1<<RUP)
 and tmp,desc
+add tmp,tmp
 add RED,tmp
 ldi tmp,(1<<GUP)
 and tmp,desc
 lsr tmp
 lsr tmp
+add tmp,tmp
 add GREEN,tmp
 ldi tmp,(1<<BUP)
 and tmp,desc
@@ -175,16 +182,19 @@ lsr tmp
 lsr tmp
 lsr tmp
 lsr tmp
+add tmp,tmp
 add BLUE,tmp
 ldi tmp,(1<<RDOWN)
 and tmp,desc
 lsr tmp
+add tmp,tmp
 sub RED,tmp
 ldi tmp,(1<<GDOWN)
 and tmp,desc
 lsr tmp
 lsr tmp
 lsr tmp
+add tmp,tmp
 sub GREEN,tmp
 ldi tmp,(1<<BDOWN)
 and tmp,desc
@@ -193,6 +203,7 @@ lsr tmp
 lsr tmp
 lsr tmp
 lsr tmp
+add tmp,tmp
 sub BLUE,tmp
 add countrgb,one
 reti
@@ -286,5 +297,72 @@ rjmp LOOP
 ; receive from uart
 ;
 UART_RECEIVE:
+cp uart_count,zero
+breq GET_MODE
+cpi uart_count,1
+breq GET_R_VALUE
+cpi uart_count,2
+breq GET_G_VALUE
+cpi uart_count,3
+breq GET_B_VALUE
+
+;
+; get mode
+;
+GET_MODE:
+in tmp,UDR
+cpi tmp,0x63 ; 0x63 = 'c'
+breq SET_CONTINUOUS_MODE
+cpi tmp,0x73 ; 0x73 = 's'
+breq SET_SPECIFY_MODE
+ldi uart_count,0
+reti
+
+;
+; set cmode
+;
+SET_CONTINUOUS_MODE:
+ldi mode,cm
+ldi uart_count,0
+reti
+
+;
+; set specify mode
+;
+SET_SPECIFY_MODE:
+ldi mode,rgb
+add uart_count,one
+; check
+out UDR,mode
+reti
+
+;
+; get red value
+;
+GET_R_VALUE:
+in RED,UDR
+add uart_count,one
+; check
+out UDR,RED
+reti
+
+;
+; get green value
+;
+GET_G_VALUE:
+in GREEN,UDR
+add uart_count,one
+; check
+out UDR,GREEN
+reti
+
+;
+; get blue value
+;
+GET_B_VALUE:
+in BLUE,UDR
+mov uart_count,zero
+; check
+out UDR,BLUE
 reti