1224 views|0 replies

2015

Posts

0

Resources
The OP
 

MSP430 - Timer_A timer interrupt program [Copy link]

1. Use the timer timing function to realize the timer single overflow interrupt and realize P3.0 square wave output

#include "cc430x613x.h"

void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P3DIR |= 0x04; // Initialize P3 port and set it to output mode

TA0CCR0 = 32768; // Define interrupt counting period 1s, clock frequency is 32.768MHZ, 32768 / 32768 = 1s
TA0CCTL0 = CCIE; // TA0CCR0 capture/compare interrupt register interrupt enable
TA0CTL = TASSEL_1 + MC_1 + TACLR; // TASSEL_1,ACLK clock source MC_1, up counting mode

_BIS_SR(LPM3_bits + GIE); // Enter LPM3 low power mode and enable total interrupt
}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void) // Timer interrupt trigger, P3 output port XOR, level flip
{
P3OUT ^= 0x04;
}

2. Use the timer timing function to realize multiple timer overflows, generate multiple interrupts accordingly, and realize P3.0 output
#include "cc430x613x.h"

void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop the watchdog timer
P3DIR |= 0x04; // Initialize P3 port and set it to output mode

TA0CCR0 = 32768; // Define interrupt counting period 1s, clock frequency is 32.768MHZ, 32768 / 32768 = 1s
TA0CCTL0 = CCIE; // TA0CCR0 capture/compare interrupt register interrupt enable

TA0CCR1 = 3276; // Define interrupt overflow period 100ms
TA0CCTL1 = CCIE; // TA0CCR0 capture/compare interrupt register interrupt enable

TA0CTL = TASSEL_1 + MC_1 + TACLR; // TASSEL_1,ACLK clock source MC_1, up-counting mode_BIS_SR

(LPM3_bits + GIE); // Enter LPM3 low power mode and enable general interrupt
}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void) // 1s overflow interrupt
{
P3OUT = ~0x04;
}

#pragma vector = TIMER0_A1_VECTOR
__interrupt void Timer_A1(void) // 100ms overflow interrupt
{
switch(TA0IV)
{
case 2:P3OUT = 0x04;break;
case 4:break;
case 10:break;
}
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list