Hardware Reference
In-Depth Information
C4
equ
5733
; delay count to generate C4 note (with 1:8 prescaler)
C4S
equ
5412
; delay count to generate C4S note
D4
equ
5108
; delay count to generate D4 note (with 1:8 prescaler)
E4
equ
4551
; delay count to generate E4 note (with 1:8 prescaler)
F4
equ
4295
; delay count to generate F4 note (with 1:8 prescaler)
F4S
equ
4054
; delay count to generate F4S note (with 1:8 prescaler)
G4
equ
3827
; delay count to generate G4 note (with 1:8 prescaler)
A4
equ
3409
; delay count to generate A4 note (with 1:8 prescaler)
B4F
equ
3218
; delay count to generate B4F note (with 1:8 prescaler)
B4
equ
3037
; delay count to generate B4 note (with 1:8 prescaler)
C5
equ
2867
; delay count to generate C5 note (with 1:8 prescaler)
D5
equ
2554
; delay count to generate D5 note (with 1:8 prescaler)
E5
equ
2275
; delay count to generate E5 note (with 1:8 prescaler)
F5
equ
2148
; delay count to generate F5 note (with 1:8 prescaler)
ZZ
equ
20
; delay count to generate an inaudible note
notes
equ
118
toggle equ
$04
; value to toggle the TC5 pin
org
$1000
delay ds.w
1
; store the delay for output-compare operation
rep_cnt ds.b
1
; repeat the song this many times
ip
ds.b
1
; remaining notes to be played
org $1500
; establish the SRAM vector address for OC5
movw
#oc5_isr,UserTimerCh5
lds
#$1500
movb
#$FF,DDRB
movb
#$90,TSCR1
; enable TCNT, fast timer flag clear
movb
#$03,TSCR2
; set main timer prescaler to 8
bset
TIOS,OC5
; enable OC5
movb
#toggle,TCTL1
; select toggle for OC5 pin action
ldx
#score
; use as a pointer to score table
ldy
#duration
; points to duration table
movb
#1,rep_cnt
; play the song twice
movb
#notes,ip
movw
2,x 1 ,delay
; start with 0th note
ldd
TCNT
; play the first note
addd
delay
;
std
TC5
;
bset
TIE,C5I
; enable OC5 interrupt
cli
;
forever pshy
; save duration table pointer in stack
ldy
0,y
; get the duration of the current note
jsr
delayby10ms
;
puly
; get the duration pointer from stack
iny
; move the duration pointer
iny
;
ldd
2,x 1
; get the next note, move pointer
std
delay
;
dec
ip
bne
forever
Search WWH ::




Custom Search