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;
}
}
|