diff --git a/MSP430Timers.pdf b/Documents/MSP430Timers.pdf old mode 100755 new mode 100644 similarity index 100% rename from MSP430Timers.pdf rename to Documents/MSP430Timers.pdf diff --git a/Documents/Makefile b/Documents/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f177b44c3da600bf24a390a09c7151e3366ed7e7 --- /dev/null +++ b/Documents/Makefile @@ -0,0 +1,41 @@ +# Project name +SOURCE = blinkrgb.c +ADDITIONAL = +# Get base name so we can create .elf file +NAME = $(basename $(SOURCE)) +# MSP430 MCU to compile for +CPU = msp430g2553 +# Optimisation level +OPTIMIZATION = -O0 +# Extra variables +CFLAGS = -mmcu=$(CPU) $(OPTIMIZATION) -std=c99 -Wall -g +# Libemb library link flags +LIBEMB = -lshell -lconio -lserial + +# Build and link executable +$(NAME).elf: $(SOURCE) $(ADDITIONAL) +ifeq (,$(findstring libemb,$(shell cat $(SOURCE)))) + msp430-gcc $(CFLAGS) -o $@ $(SOURCE) $(ADDITIONAL) +else + msp430-gcc $(CFLAGS) -o $@ $(SOURCE) $(ADDITIONAL) $(LIBEMB) +endif + msp430-objdump -D $(NAME).elf > $(NAME).hex + +# Flash to board with mspdebug +flash: $(NAME).elf + mspdebug rf2500 "prog $(NAME).elf" + +# Erase board +erase: + mspdebug rf2500 erase + +stuff: hworld.c + echo "I found hworld.c!" && cat hworld.c + +# Clean up temporary files +clean: + rm -f *.elf *.hex + +# Remote debug board +debug: $(NAME).elf + ( mspdebug rf2500 "gdb" 1>/dev/null & ); msp430-gdb $(NAME).elf -ex "target remote :2000" diff --git a/README.md b/Documents/README.md similarity index 100% rename from README.md rename to Documents/README.md diff --git a/Examples/Makefile b/Examples/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f177b44c3da600bf24a390a09c7151e3366ed7e7 --- /dev/null +++ b/Examples/Makefile @@ -0,0 +1,41 @@ +# Project name +SOURCE = blinkrgb.c +ADDITIONAL = +# Get base name so we can create .elf file +NAME = $(basename $(SOURCE)) +# MSP430 MCU to compile for +CPU = msp430g2553 +# Optimisation level +OPTIMIZATION = -O0 +# Extra variables +CFLAGS = -mmcu=$(CPU) $(OPTIMIZATION) -std=c99 -Wall -g +# Libemb library link flags +LIBEMB = -lshell -lconio -lserial + +# Build and link executable +$(NAME).elf: $(SOURCE) $(ADDITIONAL) +ifeq (,$(findstring libemb,$(shell cat $(SOURCE)))) + msp430-gcc $(CFLAGS) -o $@ $(SOURCE) $(ADDITIONAL) +else + msp430-gcc $(CFLAGS) -o $@ $(SOURCE) $(ADDITIONAL) $(LIBEMB) +endif + msp430-objdump -D $(NAME).elf > $(NAME).hex + +# Flash to board with mspdebug +flash: $(NAME).elf + mspdebug rf2500 "prog $(NAME).elf" + +# Erase board +erase: + mspdebug rf2500 erase + +stuff: hworld.c + echo "I found hworld.c!" && cat hworld.c + +# Clean up temporary files +clean: + rm -f *.elf *.hex + +# Remote debug board +debug: $(NAME).elf + ( mspdebug rf2500 "gdb" 1>/dev/null & ); msp430-gdb $(NAME).elf -ex "target remote :2000" diff --git a/blinkint.c b/Examples/blinkint.c similarity index 100% rename from blinkint.c rename to Examples/blinkint.c diff --git a/blinkrgb.c b/Examples/blinkrgb.c similarity index 100% rename from blinkrgb.c rename to Examples/blinkrgb.c diff --git a/blinksig.c b/Examples/blinksig.c similarity index 95% rename from blinksig.c rename to Examples/blinksig.c index bd2d742a347e4d5317b230ee4756c08b31e68a88..ab0e3982ea4808e5a7cc99562f90d13ef0bcd686 100644 --- a/blinksig.c +++ b/Examples/blinksig.c @@ -17,7 +17,7 @@ int main(void) // divider: 8 TA0CTL = TASSEL_2 | MC_1 | ID_3; // value: 62,500 - TA0CCR0 = 220; + TA0CCR0 = 0xF424; TA0CCR1 = 0; // enable CCR0 to interrupt TA0CCTL1 = OUTMOD_4; diff --git a/Examples/example.c b/Examples/example.c new file mode 100644 index 0000000000000000000000000000000000000000..47bb23c352ccc80ca4a75662f0ce3c85a636cb0d --- /dev/null +++ b/Examples/example.c @@ -0,0 +1,43 @@ + +// Input from dial comes through 1.4. + +#include <msp430.h> + +int main(void) +{ + WDTCTL = WDTPW | WDTHOLD; // wizard words + BCSCTL1 = CALBC1_1MHZ; + DCOCTL = CALDCO_1MHZ; + + P1DIR = BIT6; // BIT6 alternate output + P1SEL = BIT6|BIT4; // BIT4 analog input (channel 4) + + TA0CTL = TASSEL_2 | MC_1 | ID_3; // use TA0.1 for PWM on P1.6 + TA0CCR0 = 0x3FF; // 10-bit maximum value + TA0CCR1 = 0; // start off + TA0CCTL1 = OUTMOD_7; // reset/set output mode + + ADC10CTL1 = INCH_4 | ADC10DIV_3; // ADC10 channel 4, clock divider 3 + ADC10CTL0 = SREF_0 | ADC10SHT_3 | + // VCC/VSS ref, 64 x ADC10CLKs + ADC10ON | ADC10IE; // ADC10 enable, ADC10 interrupt enable + ADC10AE0 = BIT4; // analog enable channel 4 + + // __enable_interrupt(); // interrupts enabled + while(1) + { + __delay_cycles(10000); // wait for ADC ref to settle + ADC10CTL0 |= ENC + ADC10SC; // sampling and conversion start + __bis_SR_register(CPUOFF | GIE); // go to sleep with interrupts enabled + TA0CCR1 = ADC10MEM & 0x3F8; // assigns the value held in ADC10MEM to the TA0CCR1 register + } + + return 0; +} + +// ADC10 interrupt service routine +#pragma vector=ADC10_VECTOR +__interrupt void ADC10_ISR (void) +{ + __bic_SR_register_on_exit(CPUOFF); // wake up +} diff --git a/Makefile b/Makefile index 1dab6739c28af4ee8a08338fb7c6172630d16cbb..f605439d26a995e4d0be90c434fec3528d60deed 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Project name -SOURCE = blinksig.c +SOURCE = a7.c ADDITIONAL = # Get base name so we can create .elf file NAME = $(basename $(SOURCE)) diff --git a/a7.c b/a7.c new file mode 100644 index 0000000000000000000000000000000000000000..458f0ea4299a8b5109ff333d892438c27532c44d --- /dev/null +++ b/a7.c @@ -0,0 +1,55 @@ +#include <msp430.h> + +// Note: Delay_cycles appears to need a constant. Can't use a variable. + + +// Variables. +int counter = 1; + + +// Main +int main(void) +{ + WDTCTL = WDTHOLD | WDTPW; // Hold watchdog timer so it doesn't reset. + BCSCTL1 = CALBC1_1MHZ; // Calibrate cpu to 1MegaHertz + DCOCTL = CALDCO_1MHZ; // 1MegaHrtz is the slowest this can run, and technically saves power. + + // Setting P1.6 pin to output. + P1DIR |= BIT6; + // Output mode for bits, I think? + P1SEL |= BIT6; + //P1OUT = 0; + + + // Settings for configurable clock timer. + TA0CTL = TASSEL_2 | MC_1 | ID_3; + // Interupt vector. Causes periodic interupts based on timer and given value? + TA0CCR0 = 0x4000; // Frequency of toggle. + TA0CCR1 = 0x2000; + // Capture control for interupt vector. + TA0CCTL1 = OUTMOD_7; + TA0CCTL0 = CCIE; + + + __enable_interrupt(); + LPM0; + + return 0; +} + + +// Actual interupt process? +#pragma vector=TIMER0_A0_VECTOR +__interrupt void Timer0_A0_ISR (void) +{ + // If at max, decriment. + if (TA0CCR1 == 0xF424) { + counter = -1; + // Else if at min, increment. + } else if (TA0CCR1 == 0) { + counter = 1; + } + // Add counter var to vector thingy. + TA0CCTL1 += counter; +} + diff --git a/a7Test.c b/a7Test.c new file mode 100644 index 0000000000000000000000000000000000000000..cede03caf05fe3157d867ca825fd9cc97bf49e5d --- /dev/null +++ b/a7Test.c @@ -0,0 +1,64 @@ +#include <msp430.h> + +// Note: Delay_cycles appears to need a constant. Can't use a variable. + +// Takes a 1 or 0 for each input, then shifts given input to correct register. +void ChangeColors(char RED, char GREEN, char BLUE) { + P1OUT = RED << 1 | GREEN << 2 | BLUE << 3; +} + + +// Cycles through all possible color types, switching about once a second. +void CycleColors() { + ChangeColors(0, 0, 0); + __delay_cycles(1000000); // Delay for roughly a second. + ChangeColors(1, 0, 0); + __delay_cycles(1000000); // Delay for roughly a second. + ChangeColors(1, 1, 0); + __delay_cycles(1000000); // Delay for roughly a second. + ChangeColors(0, 1, 0); + __delay_cycles(1000000); // Delay for roughly a second. + ChangeColors(0, 1, 1); + __delay_cycles(1000000); // Delay for roughly a second. + ChangeColors(0, 0, 1); + __delay_cycles(1000000); // Delay for roughly a second. + ChangeColors(1, 0, 1); + __delay_cycles(1000000); // Delay for roughly a second. + ChangeColors(1, 1, 1); + __delay_cycles(1000000); // Delay for roughly a second. +} + + +// Changes brightness of led. Lower numbers are brighter. Higher are dimmer. +// Note: Any numders over 10,000 seem to start having very noticable delays between switching on and off. +void ChangeBrightness() { + ChangeColors(1, 0, 0); + __delay_cycles(10000); // Delay, determined by brightnessInt. + ChangeColors(0, 0, 0); + __delay_cycles(10000); // Delay, determined by brightnessInt. +} + + +// Main +int main(void) +{ + WDTCTL = WDTHOLD | WDTPW; // Hold watchdog timer so it doesn't reset. + BCSCTL1 = CALBC1_1MHZ; // Calibrate cpu to 1MegaHertz + DCOCTL = CALDCO_1MHZ; // 1MegaHrtz is the slowest this can run, and technically saves power. + + // Setting P1.0, P1.1, and P1.2 pins to output. + // Alternate is: P1DIR = BIT3|BIT2|BIT1; + P1DIR = 0b00001110; + // Output bits initialized to on-state. + // Alternate is: P1OUT = BIT3|BIT2|BIT1; + P1OUT = 0b00001110; + + // Intentional infinite for loop. + for (;;) { + //CycleColors(); + ChangeBrightness(); + } + + return 0; +} +