;########
.CSEG
.org 0
rjmp RESET
reti ;rjmp INT0addr = 0x0001 ; External Interrupt Request 0
reti ;rjmp INT1addr = 0x0002 ; External Interrupt Request 1
reti ;rjmp ICP1addr = 0x0003 ; Timer/Counter Capture Event
reti ;rjmp INT_BEEP_1A ;OC1Aaddr = 0x0004 ; Timer/Counter1 Compare Match A
rjmp INT_IR_40KHZ;OC1Baddr = 0x0005 ; Timer/Counter1 Compare Match B
reti ;rjmp OVF1addr = 0x0006 ; Timer/Counter1 Overflow
rjmp INT_BEEP_DURATION ;Overflow0 Interrupt Vector Address
reti ;rjmp SPIaddr = 0x0008 ; Serial Transfer Complete
rjmp INT_UART_RECIEVE ;UART Receive Complete Interrupt Vector Address
reti ;rjmp UDREaddr = 0x000a ; UART Data Register Empty
reti ;rjmp UTXCaddr = 0x000b ; UART, Tx Complete
reti ;rjmp ACIaddr = 0x000c ; Analog Comparator
;########
RESET:
;###### init SATACK
ldi temp0,0x02
out SPH,temp0
ldi temp0,0x5F
out SPL,temp0
;###############
;###### init PORT's
ldi temp0,0b11110110 ;Port PA 1,2,4..7 =out
out DDRA,temp0
ldi temp0,0b11111111 ;Port PB xxxxxxxx =out
out DDRB,temp0
ldi temp0,0b00000000 ;Port PC --- =out
out DDRC,temp0
ldi temp0,0b01110010 ;Port PD 1,4,5,6 =out
out DDRD,temp0
ldi temp0,0b10001101
out PORTD,temp0
;###############
;###### init comparator
ldi temp0,0b10000000 ; comparator power disable
out ACSR,temp0 ;
;###############
;###### init SPI
;ldi temp0,0b01010000 ; 6:SPI Enable, 4:Master Select
;out SPCR,temp0 ;
;###############
;###### init UART
; Set baud rate
;;;;; 19200 bps @ 8Mhz
ldi temp0,0x19 ; 19200 bps @ 8Mhz
ldi temp0,0x16 ; 19200 bps @ 7,19Mhz (22,4d)
out UBRR,temp0
; Enable receiver & interrupt-reciever and transmitter
ldi temp0,0b10011000; (1<<RXEN)|(1<<TXEN)
out UCR,temp0
;###############
;###### init Timer0 & Timer1
ldi temp0,0b00100010
; 1 - Timer/Counter0 Overflow Interrupt Enable
; 5 - Timer/Counter1 Output CompareB Match Interrupt Enable
out TIMSK,temp0
ldi temp0,0b00000000 ;
out TIFR,temp0
ldi temp0,0b00000101 ; start Timer0: ck/1024
out TCCR0,temp0 ; init Timer0: ck/1024
ldi temp0,0b00000000 ; disconnect Timer1 from OC1A, & OC1B
out TCCR1A,temp0
ldi temp0,0b00001001 ; clr on compare. start the Timer1/CK
out TCCR1B,temp0 ; clr on compare. start the Timer1/CK
ldi temp0,0x00
out OCR1BH,temp0
ldi temp0,VARIABLE_FOR_40_KHZ
out OCR1BL,temp0
sei
LOOP24:
nop
rjmp LOOP24
если перед
...
sei
LOOP24:
...
добавить
ldi temp0,0x00
out OCR1AH,temp0
ldi temp0,VARIABLE_FOR_40_KHZ
out OCR1AL,temp0
то всё работает замечательно.
причём в прерывание "Compare Match B" вываливается по состоянию, записанному в OCR1AH/L ....