From: Pat Thoyts Date: Thu, 4 Dec 2014 07:45:11 +0000 (+0000) Subject: Blink LED using watch crystal driven interrupts at 1s intervals X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=545dd975cf36c093a224fde96fda2fb9c76b78cd;p=vetinari_clock Blink LED using watch crystal driven interrupts at 1s intervals --- 545dd975cf36c093a224fde96fda2fb9c76b78cd diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a9362f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.elf +*~ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d46acdc --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +MCU = msp430g2111 +CC = msp430-gcc +CFLAGS=-Wall -g -Os -mmcu=$(MCU) +LDFLAGS= + +main.elf: main.c + $(CC) $(CFLAGS) -o $@ $< + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +prog: program +program: main.elf + MCU=$(MCU) mspdebug rf2500 "prog $<" + +clean: + rm -f main.elf diff --git a/main.c b/main.c new file mode 100644 index 0000000..155a72c --- /dev/null +++ b/main.c @@ -0,0 +1,49 @@ +#include +#include + +#define LED0 BIT0 /* P1.0 */ + +static void +init_leds(void) +{ + P1DIR |= LED0; /* set P1.0 as output */ + P1OUT |= LED0; /* set P1.0 low */ + + /* set timer A to use the aux clock in UP mode with ACLK/8 divider */ + TACTL = TASSEL_1 | MC_1 | ID_3; + /* set the counter to match on 511 which is 1s for 32kHz/8/8 (timer + * re-divides the interrupt clock by 8 */ + TACCR0 = 511; + /* enable the clock interrupt mode for TACCR0 match */ + TACCTL0 = CCIE; +} + +int +main(void) +{ + /* disable the watchdog */ + WDTCTL = WDTPW + WDTHOLD; + + /* external 32.768kHz crystal */ + BCSCTL1 |= DIVA_3; /* ACLK/8 */ + BCSCTL3 |= XCAP_3; /* enable 12.5pF internal capacitance */ + + init_leds(); + + /* enable global interrupts */ + eint(); + + while (1) { + /* do nothing forever, timer interrupts drive the leds */ + /* enter low power mode 3 with interrupts enabled) */ + _BIS_SR(LPM3_bits + GIE); + } +} + +interrupt(TIMER0_A0_VECTOR) +TIMERA0_ISR(void) +{ + /* clear the interrupt flag and toggle LED */ + TACCTL0 &= ~CCIFG; + P1OUT ^= LED0; +}