msp430fr5969 使用32K外部晶振定时唤醒LPM3,官方例程。

2019-03-24 10:52发布

这是我在网站找的,不知道大家是否有需要!
  1. /* --COPYRIGHT--,BSD_EX
  2. * Copyright (c) 2012, Texas Instruments Incorporated
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * *  Redistributions of source code must retain the above copyright
  10. *    notice, this list of conditions and the following disclaimer.
  11. *
  12. * *  Redistributions in binary form must reproduce the above copyright
  13. *    notice, this list of conditions and the following disclaimer in the
  14. *    documentation and/or other materials provided with the distribution.
  15. *
  16. * *  Neither the name of Texas Instruments Incorporated nor the names of
  17. *    its contributors may be used to endorse or promote products derived
  18. *    from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. *******************************************************************************
  33. *
  34. *                       MSP430 CODE EXAMPLE DISCLAIMER
  35. *
  36. * MSP430 code examples are self-contained low-level programs that typically
  37. * demonstrate a single peripheral function or device feature in a highly
  38. * concise manner. For this the code may rely on the device's power-on default
  39. * register values and settings such as the clock configuration and care must
  40. * be taken when combining code from several examples to avoid potential side
  41. * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
  42. * for an API functional library-approach to peripheral configuration.
  43. *
  44. * --/COPYRIGHT--*/
  45. //******************************************************************************
  46. //  MSP430FR59x Demo - TimerB, Toggle P1.0, CCR0 UP Mode ISR, 32KHz ACLK
  47. //
  48. //  Description: Toggle P1.0 using software and TB ISR. TimerB is
  49. //  configured for UP mode, thus the timer overflows when TBR counts
  50. //  to CCR0.
  51. //  ACLK = TACLK = 32768Hz, MCLK = SMCLK  = default DCO = ~1MHz
  52. //
  53. //
  54. //           MSP430FR5969
  55. //         ---------------
  56. //     /||               |
  57. //      | |               |
  58. //      --|RST            |
  59. //        |               |
  60. //        |           P1.0|-->LED
  61. //
  62. //   T. Witt/ P. Thanigai
  63. //   August 2012
  64. //   Built with IAR Embedded Workbench V5.30 & Code Composer Studio V5.2
  65. //******************************************************************************

  66. #include <msp430.h>

  67. int main(void)
  68. {
  69.   WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT
  70.   // XT1 Setup
  71.   PJSEL0 |= BIT4 + BIT5;
  72.   CSCTL0_H = 0xA5;
  73.   CSCTL2 = SELA_0 + SELS_3 + SELM_3;        // set ACLK = XT1; MCLK = DCO
  74.   CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0;        // set all dividers
  75.   CSCTL4 |= LFXTDRIVE_0;
  76.   CSCTL4 &= ~LFXTOFF;

  77.   do
  78.   {
  79.     CSCTL5 &= ~LFXTOFFG;
  80.                                             // Clear XT1 fault flag
  81.     SFRIFG1 &= ~OFIFG;
  82.   }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag


  83.   P1DIR |= BIT0;                            // LED interrupt
  84.   P1OUT |= BIT0;

  85.   TB0CCTL0 = CCIE;                          // TBCCR0 interrupt enabled
  86.   TB0CCR0 = 50000;
  87.   TB0CTL = TBSSEL_1 + MC_1;                 // ACLK, continuous mode

  88.   __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3 w/ interrupt
  89. }

  90. // Timer B1 interrupt service routine
  91. #pragma vector = TIMER0_B0_VECTOR
  92. __interrupt void Timer0_B0_ISR(void)
  93. {
  94.   P1OUT ^= BIT0;
  95. }
复制代码



此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
4条回答
qiushenghua
2019-03-24 20:41
< :TI_MSP430_内容页_SA7 --> 没有必要吧,CCS上大把的例程。

一周热门 更多>

相关问题

    相关文章