A lot of things happened today...
This commit is contained in:
parent
a9899a4485
commit
9c6f171102
|
@ -13,7 +13,7 @@ GDB = $(GCC_DIR)/msp430-elf-gdb
|
|||
CFLAGS = -I $(SUPPORT_FILE_DIRECTORY) -mmcu=$(DEVICE) -Os -g
|
||||
LFLAGS = -L $(SUPPORT_FILE_DIRECTORY) -T $(DEVICE).ld
|
||||
|
||||
all: prog1 prog2 adc pwm dimmer tones
|
||||
all: prog1 prog2 adc pwm dimmer tones piano
|
||||
|
||||
prog1: prog1.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $? -o prog1.elf
|
||||
|
@ -33,10 +33,13 @@ dimmer: dimmer.c
|
|||
tones: tones.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $? -o tones.elf
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $? -S -o tones.asm
|
||||
piano: piano.c
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $? -o piano.elf
|
||||
$(CC) $(CFLAGS) $(LFLAGS) $? -S -o piano.asm
|
||||
|
||||
debug: all
|
||||
$(GDB) ${EXEC}
|
||||
|
||||
clean:
|
||||
rm prog1.elf prog1.asm prog2.elf prog2.asm adc.elf adc.asm \
|
||||
pwm.elf pwm.asm dimmer.elf dimmer.asm tones.elf tones.asm
|
||||
pwm.elf pwm.asm dimmer.elf dimmer.asm tones.elf tones.asm piano.elf piano.asm
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,97 @@
|
|||
#include "msp430.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define c 1000
|
||||
#define dflat 950
|
||||
#define d 900
|
||||
#define eflat 850
|
||||
#define e 800
|
||||
#define f 750
|
||||
#define gflat 720
|
||||
#define g 670
|
||||
#define aflat 625
|
||||
#define a 600
|
||||
#define bflat 570
|
||||
#define b 535
|
||||
#define cc 500
|
||||
#define n 0
|
||||
|
||||
int hbd[30] = {
|
||||
c, n, c,
|
||||
d, c, f,
|
||||
e, c, n, c,
|
||||
d, c, g,
|
||||
f, c, n, c,
|
||||
cc, a, f,
|
||||
e, d, bflat, n, bflat,
|
||||
a, f, g,
|
||||
f, n
|
||||
};
|
||||
int hbd_lengths[30] = {
|
||||
1, 1, 1,
|
||||
3, 3, 3,
|
||||
6, 1, 1, 1,
|
||||
3, 3, 3,
|
||||
6, 1, 1, 1,
|
||||
3, 3, 3,
|
||||
3, 6, 1, 1, 1,
|
||||
3, 3, 3,
|
||||
6, 3
|
||||
};
|
||||
|
||||
int scale[13] = {
|
||||
c, dflat, d, eflat, e, f, gflat, g, aflat, a, bflat, b, cc
|
||||
};
|
||||
int scale_lengths[13] = {
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
|
||||
};
|
||||
|
||||
int whole[8] = {
|
||||
c, d, e, f, g, a, b, cc
|
||||
};
|
||||
|
||||
void play(int note) {
|
||||
if (note != 0) {
|
||||
CCR0 = note;
|
||||
CCR1 = 100;
|
||||
} else {
|
||||
CCR1 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sing(int* song, int* song_lengths, int length) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
int note = song[i];
|
||||
play(note);
|
||||
for (int j = 0; j < song_lengths[i]; j++) {
|
||||
__delay_cycles(0x3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
|
||||
|
||||
P1DIR = BIT6; // set P1.6 to output
|
||||
P1SEL |= BIT6; // P1.6 to TA0.1
|
||||
|
||||
CCTL1 = OUTMOD_7; // CCR1 reset/set
|
||||
TACTL = TASSEL_2 + MC_1; // SMCLK, up mode
|
||||
|
||||
int recording[10] = {n};
|
||||
int recording_lengths[10] = {0};
|
||||
int position = 1;
|
||||
while(position < 10) {
|
||||
if (whole[P1IN] != recording[position - 1]) {
|
||||
recording[position] = whole[P1IN];
|
||||
recording_lengths[position] = 1;
|
||||
play(recording[position]);
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
sing(recording, recording_lengths, 10);
|
||||
//clear();
|
||||
//sing(hbd, hbd_lengths, 30);
|
||||
//sing(scale, scale_lengths, 13);
|
||||
}
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#define TXD BIT2
|
||||
#define RXD BIT1
|
||||
#define LED BIT0
|
||||
#define LED BIT6
|
||||
#define IN BIT0
|
||||
|
||||
#define US 1000000
|
||||
|
||||
|
@ -23,22 +24,46 @@ void main(void) {
|
|||
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
|
||||
UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine
|
||||
|
||||
ADC10CTL0 = ADC10SHT_2 + ADC10ON; // ADC10ON
|
||||
ADC10CTL1 = INCH_0; // input A1
|
||||
ADC10AE0 |= 0x02; // PA.1 ADC option select
|
||||
|
||||
P1DIR |= TXD | LED;
|
||||
P1DIR &= ~IN;
|
||||
P1OUT |= TXD;
|
||||
P1IE |= IN;
|
||||
|
||||
TACTL = TACLR; // reset clock
|
||||
TACTL = TASSEL_2 | MC_2; // set SMCLK timer to count up at 1 MHz
|
||||
TACCTL0 = CM1 | SCS | CAP | CCIE; // set capture mode to rising edge and enable interrupts
|
||||
|
||||
//int voltage[1000];
|
||||
//int time[1000];
|
||||
while (1) {
|
||||
TAR = 0;
|
||||
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
|
||||
while (ADC10CTL1 & ADC10BUSY); // ADC10BUSY?
|
||||
//voltage[i] = ADC10MEM;
|
||||
//time[i] = TAR;
|
||||
TXByte = ADC10MEM;
|
||||
while (!(IFG2 & UCA0TXIFG));
|
||||
UCA0TXBUF = TXByte >> 2;
|
||||
__delay_cycles(100000);
|
||||
TAR = 0;
|
||||
|
||||
|
||||
P1OUT ^= LED;
|
||||
__enable_interrupt();
|
||||
__bis_SR_register(LPM0_bits + GIE);
|
||||
TXByte = US/TACCR0; // frequency in Hertz
|
||||
while (!(IFG2 & UCA0TXIFG)); // wait for TX buffer to be ready for new data
|
||||
UCA0TXBUF = (TXByte - 110)/2; // send range of 110 Hz (A below low C) to 621 Hz (D above high C)
|
||||
__delay_cycles(100000); // wait >10 ms before measuring again
|
||||
//__enable_interrupt();
|
||||
//P1IES &= ~IN; // interrupt on low to high
|
||||
//__bis_SR_register(LPM0_bits + GIE);
|
||||
//TAR = 0;
|
||||
//P1IES |= IN; // interrupt on high to low
|
||||
//__bis_SR_register(LPM0_bits + GIE);
|
||||
|
||||
//TXByte = US/TACCR0; // frequency in Hertz
|
||||
//while (!(IFG2 & UCA0TXIFG)); // wait for TX buffer to be ready for new data
|
||||
//UCA0TXBUF = (TXByte - 110)/2; // send range of 110 Hz (A below low C) to 621 Hz (D above high C)
|
||||
//__delay_cycles(100000); // wait >10 ms before measuring again
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,3 +78,17 @@ __interrupt void timer0_a0_isr(void)
|
|||
__disable_interrupt(); // disable interrupts
|
||||
__bic_SR_register_on_exit(LPM0_bits); // take us out of low power mode
|
||||
}
|
||||
|
||||
/*
|
||||
#if defined(__TI_COMPILER_VERSION__)
|
||||
#pragma vector=PORT1_VECTOR
|
||||
__interrupt void port1_isr(void)
|
||||
#else
|
||||
void __attribute__ ((interrupt(PORT1_VECTOR))) port1_isr (void)
|
||||
#endif
|
||||
{
|
||||
P1IFG = 0;
|
||||
__disable_interrupt(); // disable interrupts
|
||||
__bic_SR_register_on_exit(LPM0_bits); // take us out of low power mode
|
||||
}
|
||||
*/
|
BIN
project/main.o
BIN
project/main.o
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue