TI中文支持网
TI专业的中文技术问题搜集分享网站

MSP430 RTC

Calendar mode (RTCMODE = 1)
00b = Minute changed
01b = Hour changed
10b = Every day at midnight (00:00)
11b = Every day at noon (12:00)

更新什么 ?  不明白 请指点

Susan Yang:

您先看一下例程

/* --COPYRIGHT--,BSD_EX
* Copyright (c) 2012, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*******************************************************************************
** MSP430 CODE EXAMPLE DISCLAIMER
*
* MSP430 code examples are self-contained low-level programs that typically
* demonstrate a single peripheral function or device feature in a highly
* concise manner. For this the code may rely on the device's power-on default
* register values and settings such as the clock configuration and care must
* be taken when combining code from several examples to avoid potential side
* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
* for an API functional library-approach to peripheral configuration.
*
* --/COPYRIGHT--*/
//******************************************************************************
// MSP430F54xA Demo - RTC_A in real time clock mode
//
// Description: This program demonstrates the RTC mode by triggering an
// interrupt every second and minute. This code toggles P1.0 every second.
// This code recommends an external LFXT1 crystal for RTC accuracy.
// ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
//
// MSP430F54xA
// -----------------
// /|\ | XIN|-
// | | | 32kHz
// ---|RST XOUT|-
// | |
// | P1.0 |--> Toggles every second
// | |
//
// W. Goh
// Texas Instruments Inc.
// April 2010
// Built with CCS version 4.2 and IAR Embedded Workbench Version: 4.21.8
//******************************************************************************#include <msp430.h>int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer
P1DIR |= BIT0; // Set P1.0 as output// Initialize LFXT1
P7SEL |= 0x03; // Select XT1
UCSCTL6 &= ~(XT1OFF); // XT1 On
UCSCTL6 |= XCAP_3; // Internal load cap// Loop until XT1,XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag// Configure RTC_A
RTCCTL01 |= RTCTEVIE + RTCRDYIE + RTCBCD + RTCHOLD + RTCMODE;
// RTC enable, BCD mode, RTC hold
// enable RTC read ready interrupt
// enable RTC time event interruptRTCYEAR = 0x2010; // Year = 0x2010
RTCMON = 0x4; // Month = 0x04 = April
RTCDAY = 0x05; // Day = 0x05 = 5th
RTCDOW = 0x01; // Day of week = 0x01 = Monday
RTCHOUR = 0x10; // Hour = 0x10
RTCMIN = 0x32; // Minute = 0x32
RTCSEC = 0x45; // Seconds = 0x45RTCADOWDAY = 0x2; // RTC Day of week alarm = 0x2
RTCADAY = 0x20; // RTC Day Alarm = 0x20
RTCAHOUR = 0x10; // RTC Hour Alarm
RTCAMIN = 0x23; // RTC Minute AlarmRTCCTL01 &= ~(RTCHOLD); // Start RTC calendar mode__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 mode with interrupts
// enabled
__no_operation();
}#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(RTCIV,16))
{
case RTC_NONE: // No interrupts
break;
case RTC_RTCRDYIFG: // RTCRDYIFG
P1OUT ^= 0x01; // Toggles P1.0 every second
break;
case RTC_RTCTEVIFG: // RTCEVIFG
__no_operation(); // Interrupts every minute
break;
case RTC_RTCAIFG: // RTCAIFG
break;
case RTC_RT0PSIFG: // RT0PSIFG
break;
case RTC_RT1PSIFG: // RT1PSIFG
break;
case 12: break; // Reserved
case 14: break; // Reserved
case 16: break; // Reserved
default: break;
}
}

Susan Yang:

RTCBCD:实时时钟BCD码格式选择位,选择实时时钟的BCD格式。只能应用于日历模式(RTCMODE = 1),在计数器模式中会被忽略设置。改变这个位会将秒、分、小时、星期和年清零,将日期和月份置1。之后,实时时钟寄存器必须被软件设置。
0 :选择2进制或者十六进制1 :选择BCD码

RTCHOLD: 实时时钟保持位
0 :实时时钟(32位计数器或者是日历模式)正在运作
1 :计数器模式(RTCMODE = 0)),该位置1只会使32位计数器停止;在日历模式(RTCMODE = 1)日历以及预分频计数器会被停止。RT0PS和RT1PS、RT0PSHOLD和RT1PSHOLD位可以忽略。

RTCMODE:RTC模式选择。
0: 32位计数器模式
1:日历模式。在日历模式和计数器模式之间的切换会重置实时时钟;计数器模式切换到日历模式会将秒、分、小时、星期和年清零,将日期和月份置1。实时时钟寄存器需要后来被软件设置。RT0PS和RT1PS也会被清零。

RTCRDY:实时时钟准备位
0:实时时钟值在转换过渡(日历模式)1: 实时时钟值可被安全读取(日历模式)。在计数器模式,RTCRDY保持清除。

RTCSSEL:实时时钟源选择位。选择时钟源输入到RTC/32计数器。在RTC日历模式这两位是不考虑的,其输入默认是RT1PS的输出。00 ACLK 01 SMLK10从RT1PS输出11 从RT1PS输出

RTCTEV:RTC时间事件指示

user4740510:

回复 Susan Yang:

你好,我在msp430ware中没有找到msp430f5529 RTC的例程,请问你这个是在哪里找到的。

Susan Yang:

回复 user4740510:

我给出的是MSP430F54系列的RTC示例,可以在 dev.ti.com/…/ 查看

user4740510:

回复 Susan Yang:

麻烦你帮我看一下,我的程序进不去中断。#include <msp430.h>
#include "oled.h"int hour=0;
int min=0;
int sec=0;void main()
{WDTCTL = WDTPW + WDTHOLD;//时钟设置P1DIR |= BIT0;// ACLK set out to pinP1SEL |= BIT0;P5SEL |= BIT4+BIT5;// Select XT1UCSCTL6 &= ~(XT1OFF);// XT1 OnUCSCTL6 |= XCAP_3;// Internal load capUCSCTL3 = 0;// FLL Reference Clock = XT1// Loop until XT1,XT2 & DCO stabilizes - In this case loop until XT1 and DCo settledo{UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);// Clear XT2,XT1,DCO fault flagsSFRIFG1 &= ~OFIFG;// Clear fault flags}while (SFRIFG1&OFIFG);// Test oscillator fault flagUCSCTL6 &= ~(XT1DRIVE_3);// Xtal is now stable, reduce drive strengthUCSCTL4 |= SELA_0;// ACLK = LFTX1 (by default)RTCCTL01 |= RTCTEVIE + RTCRDYIE + RTCBCD + RTCHOLD + RTCMODE;RTCCTL0 |= RTCTEVIE + RTCRDYIE;RTCCTL1 |= RTCMODE + RTCHOLD;RTCSEC=50;//RTC初始化,定位2015.4.27/01 23:59:50RTCMIN=59;RTCHOUR=23;RTCDOW=01;RTCDAY=27;RTCMON=04;RTCYEARH = 20;RTCYEARL=15;RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode_EINT();
//__bis_SR_register( GIE);OLED_Init();OLED_Clear();while(1){OLED_ShowNum(0, 0, sec, 2, 16);OLED_ShowNum(0, 2, min, 2, 16);OLED_ShowNum(0, 4, hour, 2, 16);}
}
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)
{switch(__even_in_range(RTCIV,16)){case 2 : P3OUT ^= BIT6;//根据前面的知识,中断向量第二位是用来读时间寄存器中的值的sec = RTCSEC;//更新秒min = RTCMIN;//更新分钟hour = RTCHOUR;//更新小时break;//RTCRDYIFGcase 6 :break;}
}

赞(0)
未经允许不得转载:TI中文支持网 » MSP430 RTC
分享到: 更多 (0)