Microcontroller MSP430 - Timer_A timer interrupt program

Publisher:和谐的24号Latest update time:2018-05-04 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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 the watchdog timer  

    P3DIR |= 0x04; // Initialize P3 port and set it to output mode  

      

    TA0CCR0 = 32768; // Define the interrupt counting period as 1s, the 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 general 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 the interrupt counting period as 1s, the 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;  

    }  

}  


Keywords:MCU Reference address:Microcontroller MSP430 - Timer_A timer interrupt program

Previous article:Several ways to accurately delay the microcontroller
Next article:GPRS module and microcontroller development matters needing attention

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号