Hardware Reference
In-Depth Information
TSCR1 5 0x90;
// enable TCNT to fast timer flag clear
TSCR2 5 0x03;
// set TCNT clock prescaler to 8
TIOS
| 5 OC5;
// enable OC5
TCTL1 5 toggle;
// set OC5 pin action to toggle
delay 5 score[0];
j
5 0;
TC0
5 TCNT 1 delay;
//start an OC0 operation
TIE
| 5 C5I;
//enable TC5 interrupt
asm(“cli”);
while(score[j]){
delay 5 score[j];
delayby10ms(dur[j]);
j 11 ;
}
TIOS & 5 0xDF; //disable OC5
while(1);
}
void delayby10ms(int kk) {
char ix;
TIOS | 5 0x40;
//enable OC6
TC6 5 TCNT 1 30000;
//start OC6 operation with 20-ms delay
for(ix 5 0; ix < kk; ix 11 ){
while(!(TFLG1 & 0x40));
TC6 15 30000;
}
TIOS & 5 0xBF; //disable OC6
}
interrupt void tc5ISR(void) {
TC5 15 delay;
}
The function for setting up the interrupt vector for OC5 is as follows:
extern void near tc5ISR(void);
#pragma CODE_SEG __NEAR_SEG NON_BANKED
#pragma CODE_SEG DEFAULT // Change code section to DEFAULT.
typedef void (*near tIsrFunc)(void);
const tIsrFunc _vect[] @0xFFE4 5 {
tc5ISR
};
There are at least two drawbacks in using this method to play a song.
1. A periodic square waveform is only an approximation to an actual note. Those who
have learned communication theory know that a periodic square waveform also
contains harmonics with higher frequencies. The solution to this problem is beyond
the scope of this text.
2. There is no loudness control. Using the PWM function rather than the output-
compare function and adjusting the duty cycle of each note is one of the possible
solutions to this problem.
 
Search WWH ::




Custom Search