; 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
; 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