⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msp430x54x_rtc_01.c

📁 MSP430F5XXX的sample code
💻 C
字号:
//******************************************************************************
//  msp430FG5438 Demo - Real Time Clock, Toggle P1.0 Inside ISR, 32kHz ACLK
//
//  Description: This program toggles P1.0 by xor'ing P1.0 inside of
//  a Real Time Clock ISR. The Real Time Clock ISR is called once a minute using
//  the Alarm function provided by the RTC. ACLK used to clock basic timer.
//  ACLK = REFO = 32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
//
//                msp430FG5438
//             -----------------
//         /|\|                 |
//          | |                 |
//          --|RST              |
//            |                 |
//            |             P1.0|-->LED
//
//   M Smertneck
//   Texas Instruments Inc.
//   April 2008
//   Built with CCEv3.2 IAR Embedded Workbench Version: 3.42A
//******************************************************************************

#include <msp430x54x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop Watchdog Timer

  RTCCTL01 = RTCBCD+RTCHOLD+RTCMODE+RTCTEVIE+RTCAIE;
                                        // RTC enable, BCD mode,
                                        // alarm every Minute,
                                        // enable RTC interrupt
  // Init time
  RTCSEC =  0x00;                       // Set Seconds
  RTCMIN =  0x32;                       // Set Minutes
  RTCHOUR = 0x10;                       // Set Hours

  // Init date
  RTCDOW =  0x03;                       // Set DOW
  RTCDAY =  0x30;                       // Set Day
  RTCMON =  0x04;                       // Set Month
  RTCYEAR = 0x2008;                     // Set Year

  RTCCTL01 &= ~RTCHOLD;                 // Enable RTC

  P1DIR |= 0x01;                        // Set P1.0 to output direction

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

// Basic Timer interrupt service routine
#pragma vector=RTC_VECTOR
__interrupt void RTC(void)
{
  P1OUT ^= 0x01;                        // Toggle P1.0 using exclusive-OR
  RTCCTL01 &= ~RTCTEVIFG;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -