
#include <msp430.h>
#include <stdint.h>

#define interrupt(x) void __attribute__((interrupt (x)))


void ConfigTimerA(uint16_t delayCycles)
{
	TACCTL0 |= CCIE;	// Enable Interrupts on Timer
	TACCR0 = delayCycles;	// Number of cycles in the timer
	TACTL |= TASSEL_1;	// Use ACLK as source for timer
	TACTL |= MC_1;		// Use UP mode timer
}


interrupt(TIMER0_A0_VECTOR) timer_A0(void)
{
	_bic_SR_register_on_exit(LPM3_bits); // do not enter sleep mode
} 


int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

	BCSCTL1 = CALBC1_1MHZ;          // Set range
	DCOCTL = CALDCO_1MHZ;  		// Set DCO step + modulation

	BCSCTL3 |= LFXT1S_2;		// LFXT1 = VLO
        IFG1 &= ~OFIFG;
	BCSCTL2 |= SELM_0 + DIVM_3;

	P1DIR = 0xff;			// Set P1.x to output
	P1OUT = 0;
	P2DIR = 0xc0;			// Set P2.x to output
	P2OUT = 0;

	ConfigTimerA(100);
	for(;;) {
		P1OUT = 0x20;
		_NOP();
		_NOP();
		_NOP();
		_NOP();
		_NOP();
		_NOP();
		P1OUT = 0;
	        _bis_SR_register(LPM3_bits + GIE); // Enter Low Power Mode 3 with interrupts
	}
	
	return 0;
}
