#include <msp430.h>
#define OUTPUT_PIN BIT0
/*
* main.c
*
* Testing timer_0 interrupt to toggle LED (P1.0)
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= OUTPUT_PIN; // Set P1.0 and P1.6 to output direction
P1OUT |= OUTPUT_PIN;
P1OUT ^= (OUTPUT_PIN);
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
CCTL0 = CCIE;
TACTL = TASSEL_2 + ID_3 + MC_1; // Set the timer A to SMCLCK, UP to TACCR0, Input Divider: /8
TACCR0 = 50000-1; // 50ms @(8MHz/8)
__enable_interrupt();
__bis_SR_register(LPM0 + GIE); // LPM0 with interrupts enabled
while(1);
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
static unsigned char ucCount = 0;
if(ucCount++ >= 20){
P1OUT ^= OUTPUT_PIN;
ucCount = 0;
}
}
2016年10月24日 星期一
MSP430 LaunchPad Timer_0 Interrupt
Using Timer_0 Interrupt to Toggle LED on MSP430 LaunchPad
訂閱:
文章 (Atom)