;Нажимая на кнопки будут звучать ноты - до,ре,ми,фа,соль,ля,си.
.include "tn2313def.inc"
.list
.def temp=r16
.def count=r17
.cseg
.org 0
start: rjmp init
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
reti
init: ldi temp,ramend
out spl,temp
ldi temp,0x08
out ddrb,temp
ldi temp,0
out ddrd,temp
out portb,temp
ldi temp,0x7f
out portd,temp
ldi temp,0x80
out acsr,temp
ldi temp,0b00001001
out tccr1b,temp
m1: ldi temp,0
out tccr1a,temp
main: clr count
in temp,pind
m2: lsr temp
brcc m3
inc count
cpi count,7
brne m2
rjmp m1
m3: lsl count ;умножение на 2 (номер кнопки)*2
mov yl,count ;формула для вычесления адреса tabkd адрес=tabkd*2+(номер кнопки)*2
ldi yh,0
ldi zl,low(tabkd*2)
ldi zh,high(tabkd*2)
add zl,yl
adc zh,yh
lpm yl,z+
lpm yh,z
out ocr1ah,yh
out ocr1al,yl
ldi temp,0b01000000
out tccr1a,temp
rjmp main
tabkd: .dw 4748,4228,3768,3556,3168,2822,251