You will construct a one-octave, single voice,
square-wave output, keyboard synthesizer.
The keyboard
will produce the musical notes corresponding to:
C4 262 Hz (middle C)
D4 294
E4 330
F4 349
G4 392
A4 440
B4 494
C5 523
Procedure:
You will need to connect the switches to PortB of the mcu so that you can use all eight switches. One bit of PortD, perhaps bit 6 (which happens to be adjacent on the connector to ground), will be used to drive an earphone.
The interrupt-driven timer described in the first lab will be modified to produce one interrupt per 1/2 cycle of the desired audio tone. Be sure to use a pre-scaler value which maximizes the frequency accuracy of your tones. The interrupt routine should toggle the audio output bit. The output bit can drive the earphone directly, but is somewhat loaded by the earphone. You can make it louder by using a 74xx driver or an op-amp.
When you do part 2 of the assignment below, you will need to index into an array which contains the notes the human has entered. Use the instructions:
ld reg, Z ;copies the contents of (Z) to reg st Z, reg ;copies the contents of reg to (Z)to access the array. The indirect Z register is r30 on this mcu and contains the register number you wish to read/write. For instance if the Z register contains 0x0f, then the
ld
instruction will copy the contents
of r15 to reg
. Since r16 to r31 are somewhat more general than
r0 to r15, you will probably want to use r0 to r15 to store the array of
notes.
When you demonstrate the keyboard to a staff member, you will play a scale and a short melody of your choice. You may use the melody shown below. The keyboard needs to produce only one note at a time (single voice).
Notes: E E E F F G F E D E F G C F E D C C Play the hollow notes twice as long as the filled notes.Play the melody.