
Chapter 6
SCH1PCM_STOP:
BC 0x20, 4
; set stop flag in R20
RETS
6.9 Playing Melody
As explained in the chapter on
Special Function Control
(Chapter 4), four
melody channels are provided for instrument melody playback. You can set up
the Melody Function Control registers and use the MTC timer interrupt to
handle the tempo, rhythm, and note data access. Because the tempo is
controlled by the time interval of the MTC timer interrupt, you need to set a
proper pre-scale ratio and counter value. The tone and envelope can be
controlled by the MTC interrupt subroutine.
The following steps shows how it is done.
1. Prepare the MTC interrupt subroutine. The MTC subroutine plays the tone
of the current note, calculates the beat and envelope, and accesses new data
for the next note.
2. Select the DAC control registers by setting R9. Set the volume and assign
the melody channel, then turn on the DACs.
3. Set the MTC pre-scale ratio and counter re-load value for desired tempo
value.
4. Enable the MTC timer interrupt and enter into end-of-melody wait
condition.
The following example demonstrates a melody playback. You have to prepare
the interrupt subroutine in advance. Once playback starts, the main program
enters a waiting loop and polls for the “active flag” you have previously
defined.
6.9.1 Example - Playing Melody
;--------------------------------------------------------------
; This example demonstrates playing melody in Channel 1. The
; user has to set up the melody playback control in the main
; program and prepare a beat/tone/envelope subroutine in the MTC
; interrupt. The example assumes user has already stored the
; melody code in the voice ROM at address 0x02000. System clock
; Fosc = 4MHz
;--------------------------------------------------------------
ORG
0x0000
JMP POWERON
; go to power-on procedure
ORG 0x0002
; timer interrupt vector
96
•
Software Application
EM60000Series User’s Manual