Skip to content
Snippets Groups Projects
Commit b23f4fcc authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

I have no idea what I'm doing. All I can do is make it blink

parent fc624672
Branches
No related merge requests found
File moved
# 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"
File moved
# 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"
File moved
File moved
......@@ -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;
......
// 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
}
# Project name
SOURCE = blinksig.c
SOURCE = a7.c
ADDITIONAL =
# Get base name so we can create .elf file
NAME = $(basename $(SOURCE))
......
a7.c 0 → 100644
#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;
}
a7Test.c 0 → 100644
#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;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment