]> hackdaworld.org Git - my-code/atmel.git/commitdiff
/* no comment */
authorhackbard <hackbard>
Wed, 25 Oct 2006 20:40:05 +0000 (20:40 +0000)
committerhackbard <hackbard>
Wed, 25 Oct 2006 20:40:05 +0000 (20:40 +0000)
beginners/light_control.asm
beginners/s90_to_tiny.inc

index 432ca7d97751bed4670d8188e490a0af66d63850..2c707367aebe0f5ef5ecf5955d3832b54b8eff92 100644 (file)
@@ -7,14 +7,17 @@
 ; specify device
 .include "../include/2313def.inc"
 
+; for register/bit definitions compatibility
+.include "./s90_to_tiny.inc"
+
 ; ------------------
 ; interrupt vectors:
 ; ------------------
 
 ; reset
-rjmp RESET
+rjmp INIT
 ; int0
-reti
+rjmp INT_ROUTINE
 ; int1
 reti
 ; timer 1 capture
@@ -54,47 +57,89 @@ reti
 ; code:
 ; -----
 
-RESET:
+INIT:
        ; set stackpointer
        ldi r16,low(RAMEND)     ; write top of ramend (lowbyte)
        out SPL,r16             ; to stackpointer
 
        ; rs232 init
-       ldi r16,12      ; "38.4k bps @ 8 mhz" in r16
-       out UBRR,r16    ; write to uart baudrate register
+       ldi r16,0
+       out UBRRH,r16
+       ldi r16,12      ; "38.4k bps @ 8 mhz" / "4.8k bps @ 1 mhz"
+       out UBRRL,r16   ; write to uart baudrate register
        ldi r16,(1<<RXEN)|(1<<TXEN)|(1<<RXCIE)  ; enable rx/tx + rx interrupt
        out UCSRB,r16   ; write to uart control register
 
-       ; pwm (OC0A=PB2 OC0B=PD5)
-       ; set as output
-       ldi r16,(1<<DDB2)
-       out DDRB,r16
-       ldi r16,(1<<DDD5)
+       ; int0
+       ldi r16,(1<<PD2)        ; int0 input
        out DDRD,r16
-       ; output 0
-       ldi r16,(1<<PINB2)
-       subi r16,0xff
-       out PORTB,r16
-       ldi r16,(1<<PIND5)|(1<<PIND6)
-       subi r16,0xff
+       ldi r16,(1<<PD2)        ; int0 pull-up
        out PORTD,r16
-       ; toggle OC0A/B on compare match / fast pwm
-       ldi r16,(1<<COM0A0)|(1<<COM0B0)|(1<<WGM00)|(1<<WGM01)
-       out TCCR0A,r16
-       ; top in OCR0A / no clock prescaling
-       ldi r16,(1<<WGM02)|(1<<CS00)
-       ; overflow interrupt enable
-       
-       ; initial pwm value 0x7f
-       ldi r16,0x7f
-       out OCR0A,r16
-       out OCR0B,r16
+       ldi r16,0               ; interrupt on low level of int0
+       out MCUCR,r16
+       ldi r16,(1<<INT0)       ; ir enable
+       out GIMSK,r16
+
+       ; port config
+       ldi r16,0               ; output
+       out DDRB,r16
+       ldi r16,0xff            ; pull high
+       out PORTB,r16
+
+       ; some initial values
+       ldi r20,0
+       ldi r17,0xff
+       ldi r25,0x4c
 
        ; global interrupt enable
        sei
 
 MAIN:
+       out PORTB,r17
+       
        rjmp MAIN
 
+
 UART_RX:
+       in r29,UDR
+       UART_OUT:
+               sbis UCSRA,UDRE
+               rjmp UART_OUT
+               out UDR,r29
+       reti
+
+
+INT_ROUTINE:
+       ldi r16,0               ; disable int0
+       out GIMSK,r16
+       cpi r17,0xff            ; toggle light
+       breq TURN_ON
+       TURN_OFF:
+               ldi r17,0xff    ; turn off light
+               ldi r25,0x44    ; D
+               rjmp CONTINUE
+       TURN_ON:
+               ldi r17,0       ; turn on light
+               ldi r25,0x4c    ; L
+       CONTINUE:
+               out PORTB,r17
+               sbis UCSRA,UDRE
+               rjmp CONTINUE
+               out UDR,r25
+       ldi r20,0
+       WAIT:
+               ldi r21,0
+               WAIT_II:
+                       inc r21
+                       cpi r21,0xff
+                       brne WAIT_II
+               inc r20
+               cpi r20,0xff
+               brne WAIT
+
+       ldi r16,(1<<INT0) ; (re)activate int0
+       out GIMSK,r16
+
        reti
+               
+; eof
index 7900ada9a825d56b5ae3cf687fdb2806c1380a37..f08715f75a2a8925199b05a1f779889791a12342 100644 (file)
 
 ; uart
 ;#####
+.equ   UBRRL   =UBRR   ; 09
+.equ   UBRRH   =$02
 .equ   UCSRA   =USR    ; 0b
 .equ   UCSRB   =UCR    ; 0a
 
-; 8 bit timer counter register
-;#############################
+; 8/16 bit timer counter registers
+;#################################
 .equ   TCCR0A  =$30
 ;-------------------
 .equ   WGM00   =$00
@@ -42,7 +44,9 @@
 .equ   OCR0B   =$3c
 ;-------------------
 
-
-
-
+; TIMSK
+;------
+.equ   OCIE0A  =$00
+.equ   OCIE0B  =$02
+.equ   OCIE1B  =$05