Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MSP430 Launchpad TimerA Interrupt Example

Status
Not open for further replies.
Thought I would post some code for those Launchpad owners out there using CCS. I could become a convert,........ once I get the C syntax down. Actually using the debugger now, because I'm getting nailed left and right on stupid mistakes.

I was needing to put my chip to sleep, and wake up every 10 minutes or so to check on some inputs. So here is the code that comes within a handful of seconds of doing so.

Code:
//A rough 10 minute timer example using the MSP430_Launchpad
//Utilizes TIMERA0 interrupt, and the low power VLOCLK (12khz)
//CCS v4.1.3.xx

#include "msp430g2211.h"
#define LED0 BIT0
unsigned char count = 0;

void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;		// Stop WDT
    P1DIR |= 0xFF;			//All outputs
    P1OUT = 0;
    BCSCTL3 = LFXT1S1;			//Select VLOCLK for ACLCK (i.e. 12khz intosc)
    P1OUT |= LED0;
    TACCTL0 = OUTMOD_2 + CCIE;		// TACCR0 interrupt enabled
    TACCR0 = 32768;	//Compare to Timer_A register (approx. 25 sec for VLOCLK & 1/8 divider)
    TACTL = TASSEL_1 + ID1 + ID0 + MC_1;    // ACLCK, 1/8 DIVIDER, upmode to TCCR0 value

for(;;)
{
  __bis_SR_register(LPM3_bits + GIE);    //Enter LPM3 w/interrupt
  __no_operation();		// For debugger, executes next instruction just like a PIC
}
}

#pragma vector=TIMERA0_VECTOR		// Timer A0 interrupt service routine
__interrupt void Timer_A (void)
{
	count += 1;
	TACCR0 = 32768;			// reset TACCR0 register
	if (count==24){			//24 * 25sec is approx. 10 minutes
		P1OUT ^= LED0;		//Toggle LED
		count = 0;
	}
}
 
Why don't you place the LPM instruction outside the for loop!
no need to execute repeatedly the instruction in infinite loop.
 
Last edited by a moderator:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top