Added end_record for disabling timer interrupts, turning off LED1, and playing nothing at end of recording.

This commit is contained in:
Jonathan Chan 2018-03-22 21:58:38 -07:00
parent ec7bd45097
commit ea2d661bb6
1 changed files with 11 additions and 7 deletions

View File

@ -27,9 +27,7 @@
#define CSINT 6 // centiseconds storable in int of microseconds #define CSINT 6 // centiseconds storable in int of microseconds
#define USINT 60000 // CSINT in microseconds #define USINT 60000 // CSINT in microseconds
#define DUTY 250 #define MAXNOTES 0x4D // not enough RAM to allocate any more to rec, len :(
#define DELAY 1000 // input sample delay in microseconds
#define MAXNOTES 0x40 // record at most 64 notes (arbitrary)
// max length of note is 0xFFFF centiseconds = approx. 10 minutes // max length of note is 0xFFFF centiseconds = approx. 10 minutes
unsigned int rec[MAXNOTES]; // notes recorded unsigned int rec[MAXNOTES]; // notes recorded
@ -51,7 +49,7 @@ unsigned int whole[8] = {
void play(unsigned int note) { void play(unsigned int note) {
if (note != n) { if (note != n) {
CCR0 = note; CCR0 = note;
CCR1 = DUTY; CCR1 = 250;
} else { } else {
CCR0 = 0xFFFF; // cannot count to 0; set to max CCR0 = 0xFFFF; // cannot count to 0; set to max
CCR1 = 0; CCR1 = 0;
@ -72,6 +70,12 @@ void save_length(unsigned int position) {
cs = us = TAR = 0; // reset all counts cs = us = TAR = 0; // reset all counts
} }
void end_record() {
P1OUT &= ~LED1;
TACCTL0 &= ~CCIE;
play(n);
}
void record() { void record() {
unsigned int note; unsigned int note;
TAR = 0; TAR = 0;
@ -84,8 +88,9 @@ void record() {
play(note); play(note);
notes++; notes++;
} }
__delay_cycles(DELAY); __delay_cycles(1000);
} }
end_record();
} }
void main(void) { void main(void) {
@ -135,8 +140,7 @@ __interrupt void port1_isr(void)
if (recording) { if (recording) {
save_length(notes); save_length(notes);
recording = false; recording = false;
P1OUT &= ~LED1; end_record();
TACCTL0 &= ~CCIE; // disable interrupts for clock
} }
playback(); playback();
P1IFG &= ~BUTTON; // set interrupt flag to 0 P1IFG &= ~BUTTON; // set interrupt flag to 0