Skip to content
Snippets Groups Projects
Commit 7cd1b672 authored by Chris Sphinx's avatar Chris Sphinx
Browse files

initial commit

parents
Branches
No related merge requests found
Makefile 0 → 100644
# Project name
SOURCE = adclight.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 -fomit-frame-pointer
# 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"
#include <msp430.h>
// The Best Lack All Conviction,
// While the Worst Are Full of Passionate Intensity
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
}
#include <msp430.h>
// The Best Lack All Conviction,
// While the Worst Are Full of Passionate Intensity
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_4; // 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
TA0CCR0 = 0x3FF -(ADC10MEM & 0x3F8);// assigns the value held in ADC10MEM to the TA0CCR0 register
}
return 0;
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // wake up
}
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