楼主可参考下我这个例程的。。。。。。
//******************************************************************************
// MSP430x530x Demo - Enters LPM3 with ACLK = LFXT1, REF0 disabled,
// VUSB LDO and SLDO disabled, SVS disabled
//
// Description: Configure ACLK = LFXT1 and enters LPM3. Measure current.
// ACLK = LFXT1 = 32kHz, MCLK = SMCLK = default DCO
//
// MSP430F530x
// -----------------
// /|\ | XIN|-
// | | | 32kHz
// ---|RST XOUT|-
// | |
//
// B. Nisarga
// Texas Instruments Inc.
// Dec 2010
// Built with CCSv4.2 and IAR Embedded Workbench Version: 4.21
//******************************************************************************
#include <msp430f5310.h>
#define uchar unsigned char
#define uint unsigned int
#define SYS14_WORKAROUND // Comment this line if silicon revision has SYS14 bug fixed
#ifdef SYS14_WORKAROUND
#define INIT_MEMORY_ADDR 0x0900
unsigned int *Address = ((unsigned int*)INIT_MEMORY_ADDR);
#endif
#define GREEN_ON P6OUT |=BIT2 //P6.2
#define GREEN_OFF P6OUT &=~BIT2
#define GREEN_ON_OFF P6OUT ^=BIT2
#define RED_ON P6OUT &=~BIT3 //P6.3
#define RED_OFF P6OUT |=BIT3
#define RED_ON_OFF P6OUT ^=BIT3
typedef struct {
uint year ; //
uchar month; //
uchar day; //
uchar week;
uchar hour; //
uchar min; //
uchar second;
uchar flag;
} time;
time RTC;
uchar flag =0;
void Init_Rtc(void)
{ // BCD码日历格式输出
RTCCTL01 = RTCBCD + RTCHOLD + RTCMODE + RTCTEV_0 ;
RTCPS0CTL = RT0PSHOLD ; //配置两个计数器分频
RTCPS1CTL = RT1PSHOLD ;
RTCSEC = 0x54; //初始化秒
RTCMIN = 0x59 ; //初始化分钟
RTCHOUR = 0x12; //初始化小时
RTCDOW = 0x01;
RTCDAY = 0x15; //日期初始化
RTCMON = 0x02 ; //初始化月份
RTCYEAR = 0x2013; //初始化年份
RTCAMINHR = 0x2200 + BIT7; //闹钟小时和分钟设置
RTCADOWDAY = 0x2402; //闹钟星期和日期设置
RTCCTL01 &= ~RTCHOLD; //打开RTC模块
RTCPS0CTL &= ~RT0PSHOLD; //打开RTCPS0CTL
RTCPS1CTL &= ~RT1PSHOLD; //打开RTCPS1CTL
RTCCTL0 |= RTCAIE + RTCRDYIE; //打开安全访问使能 ,闹钟使能
}
void TimerB_Init(void) //Timerb 定时中断初始化,主要用于系统任务定时分配*****************
{
TBCTL = TBSSEL_1 + MC_1 + ID_2; // 时钟源为ACLK=32768Hz, 增计数模式,4分频--8192 //使能定时器溢出中断
TBCCR0 =41; //0.005s
//TBCCR0 =8; //0.001s
// TBCCR0 = 409-1; //0.05s
// TBCCR0 = 819; //0.1s
// TBCCR0 = 4096-1; //0.5s
//TBCTL = TBSSEL_2 + MC_1 + ID_3; // 时钟源为SMCLK=8MHz, 增计数模式,8分频 //使能定时器溢出中断
//TBCCR0 = 50000-1; //定时0.05S
}
|