MSP430F5438 study notes timer TA1 compare match CCR0

Publisher:advancement3Latest update time:2018-04-28 Source: eefocusKeywords:MSP430F5438 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  1. // Clock defaults  

  2. // FLL clock FLL select XT1  

  3. // Auxiliary clock ACLK selects XT1 32768Hz  

  4. // Main system clock MCLK selection DCOCLKDIV 8000000Hz  

  5. // Subsystem clock SMCLK selection DCOCLKDIV 8000000Hz  

  6. // TA1 selects ACLK, the maximum count value is 16384, and the interrupt frequency is 2HZ  

  7. // Toggle P4.0 in TIMER1_A0_VECTOR  

  8.   

  9. #include   

  10. #include   

  11. void clock_config(void);  

  12. void select_xt1(void);  

  13. void dco_config(void);  

  14.   

  15. int main(void)  

  16. {  

  17.     clock_config(); // Initialize the clock  

  18.     P4DIR |= BIT0; //P4.0 output  

  19.   

  20.     TA1CCTL0 = CCIE; // Enable TA1CCR0, compare match interrupt  

  21.     TA1CCR0 = 16384; // Initialize the maximum value, the compare match interrupt frequency occurs 32768/16384 = 2Hz  

  22.     TA1CTL = TASSEL_1 + MC_1 + TACLR; // Select ACLK, the maximum value is CCR0, clear the count value  

  23.   

  24.     _EINT(); // Initialize global interrupt  

  25.   

  26.     while(1)  

  27.     {  

  28.         ;  

  29.     }  

  30. }  

  31.   

  32. void clock_config(void)  

  33. {  

  34.     WDTCTL = WDTPW + WDTHOLD; // Stop watchdog  

  35.     select_xt1(); // Select XT1  

  36.     dco_config(); // ACLK = XT1 = 32.768K  

  37.                                                 // MCLK = SMCLK = 8000K  

  38. }  

  39.   

  40. void select_xt1(void)  

  41. {  

  42.     // Start XT1  

  43.     P7SEL |= 0x03; // P7.0 P7.1 peripheral function  

  44.     UCSCTL6 &= ~(XT1OFF); // XT1 is turned on  

  45.     UCSCTL6 |= XCAP_3; // Internal capacitor  

  46.     do  

  47.     {  

  48.         UCSCTL7 &= ~XT1LFOFFG; // Clear XT1 error flag  

  49.     }while (UCSCTL7&XT1LFOFFG); // Check XT1 error flag  

  50. }  

  51.   

  52. void dco_config(void)  

  53. {  

  54.     __bis_SR_register(SCG0); // Disable FLL function  

  55.     UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx  

  56.     UCSCTL1 = DCORSEL_5; // DCO maximum frequency is 16MHz  

  57.     UCSCTL2 = FLLD_1 + 243; // Set DCO frequency to 8MHz  

  58.                                                 // MCLK = SMCLK= Fdcoclkdiv = (N+1)X(Ffllrefclk/n)  

  59.                                                 // N is the only value that needs to be calculated  

  60.                                                 // Ffllrefclk FLL reference clock, default is XT1  

  61.                                                 // n takes the default value, which is 1  

  62.                                                 // (243 + 1) * 32768 = 8MHz  

  63.     __bic_SR_register(SCG0); // Enable FLL function  

  64.   

  65.     // Necessary delay  

  66.     __delay_cycles(250000);  

  67.   

  68.     // Clear the error flag  

  69.     do  

  70.     {  

  71.         UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);  

  72.                                                 // Clear all oscillator error flags  

  73.         SFRIFG1 &= ~OFIFG; // Clear oscillator error  

  74.     }while (SFRIFG1&OFIFG); // Wait for clear completion  

  75. }  

  76.   

  77. #pragma vector=TIMER1_A0_VECTOR  

  78. __interrupt void TIMER1_A0_ISR(void)  

  79. {  

  80.     P4OUT ^= BIT0;  


Keywords:MSP430F5438 Reference address:MSP430F5438 study notes timer TA1 compare match CCR0

Previous article:I2C Operation Notes - Taking AT24C04 as an example
Next article:MSP430F5438A instruction cycle and clock cycle

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号