/************************************************************/
/******* 样例使用说明 *************/
/******* 版本历史 ************/
/******* 日期 版本 负责人 IAR MDK ***********/
/***** 017-07-14 0.1 CJ 7.70 5.14 **********/
/******* QQ:3396208645 ************/
/******* 功能描述 ***********/
/* 本样例主要涉及时钟模块计数寄存器的写入和读取**********/
/*说明: *************/
/*计数初值写入计数寄存器 *************/
/*启动计数 *************/
/*读取计数寄存器数值 *************/
/******* 测试环境 *************/
/* 测试用板: *************/
/* SK-L110-TSSOP20 V10 *************/
/*******辅助工具: ************/
/* JLINK调试工具 *************/
/************************************************************/
#define IS_VALID_CLK(x) (RtcClk32768 == (x)||\
RtcClk32768_1== (x)||\
RtcClk32== (x)||\
RtcClk32_1== (x)||\
RtcClkHxt128 ==(x)||\
RtcClkHxt256 == (x)||\
RtcClkHxt512 == (x)||\
RtcClkHxt1024 == (x))
#define IS_VALID_CYCSEL(x) (RtcPrads == (x)||\
RtcPradx==(x))
#define IS_VALID_PRDS(x) (Rtc_None == (x)||\
Rtc_05S == (x)||\
Rtc_1S == (x)||\
Rtc_1Min ==(x)||\
Rtc_1H == (x)||\
Rtc_1Day ==(x)||\
Rtc_1Mon ==(x)||\
Rtc_1Mon_1 ==(x))
#define IS_VALID_IRQ_SEL(x) (RtcPrdf== (x) ||\
RtcAlmf== (x))
#define IS_VALID_FUNC(x) ((RtcCount<=(x))&&\
(Rtc1HzOutEn>=(x)))
#define CkDateTime 0x7F
#define CkDate 0x78
#define CkTime 0x07
#define RTC_TIMEOUT 1000//test 1s
#define T1_PORT (3)
#define T1_PIN (3)
uint8_t cyccnt=0;
uint8_t u8Alarmcnt=0;
uint8_t **=0;
stc_rtc_time_t stcReadTime;
/********************************************************************************** \brief RTC计数时钟选择
** ** \param [in] enClk时钟源
** ** \retval Ok
******************************************************************************/
en_result_t Rtc_SelClk(en_rtc_clk_t enClk)
{
en_result_t enRet = Error;
ASSERT(IS_VALID_CLK(enClk));
M0P_RTC->CR1_f.CKSEL = enClk;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
**\brief RTC周期中断方式选择
**
**\param [in] pstccCyc周期中断方式及周期间隔选择
**
**\retval Ok
**
******************************************************************************/
en_result_t Rtc_SetCyc(stc_rtc_cyc_sel_t*pstcCyc)
{
en_result_t enRet = Error;
ASSERT(IS_VALID_CYCSEL(pstcCyc->enCyc_sel));
ASSERT(IS_VALID_PRDS(pstcCyc->enPrds_sel));
M0P_RTC->CR0_f.PRDSEL= pstcCyc->enCyc_sel;
if(pstcCyc->enCyc_sel)
{
M0P_RTC->CR0_f.PRDX = pstcCyc->u8Prdx;
}
else
{
M0P_RTC->CR0_f.PRDS= pstcCyc->enPrds_sel;
}
enRet = Ok;
returnenRet;
}
/**
******************************************************************************
**\brief RTC时制选择
**
**\param [in] bmode是12时制or24时制
**
**\retval Ok 设置正常
**\retval ErrorInvalidParameter 设置异常
******************************************************************************/
en_result_t Rtc_SetAmPm(en_rtc_ampm_tenMode)
{
en_result_t enRet = Error;
switch(enMode)
{
case 0:
case 1:
M0P_RTC->CR0_f.AMPM = enMode;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
**\brief RTC闹钟中断设置
**
**\param [in] pstcAlarmTime闹钟时间时、分、周
**
**\retval Ok 设置正常
**
******************************************************************************/
en_result_tRtc_SetAlarmTime(stc_rtc_alarmset_t* pstcAlarmTime)
{
en_result_t enRet = Ok;
ASSERT(NULL != pstcAlarmTime);
if(Rtc12h == M0P_RTC->CR0_f.AMPM)
{
enRet = Check_BCD_Format(pstcAlarmTime->u8Hour,0x00,0x12);
}
else
{
enRet = Check_BCD_Format(pstcAlarmTime->u8Hour,0x00,0x24);
}
if(enRet != Ok)
return enRet;
enRet = Check_BCD_Format(pstcAlarmTime->u8Minute,0x00,0x59);
if(enRet != Ok)
return enRet;
//enRet = Check_BCD_Format(pstcAlarmTime->u8Week,0x00,0x06);
if(enRet != Ok)
return enRet;
M0P_RTC->ALMHOUR = pstcAlarmTime->u8Hour;
M0P_RTC->ALMMIN = pstcAlarmTime->u8Minute;
M0P_RTC->ALMWEEK = pstcAlarmTime->u8Week;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
**\brief RTC闹钟中断时间获取
**
**\param [in] pstcAlarmTime闹钟时间时、分、周
**
**\retval Ok 设置正常
**
******************************************************************************/
en_result_tRtc_GetAlarmTime(stc_rtc_alarmset_t* pstcAlarmTime)
{
en_result_t enRet = Error;
ASSERT(NULL != pstcAlarmTime);
pstcAlarmTime->u8Minute = M0P_RTC->ALMMIN;
pstcAlarmTime->u8Hour = M0P_RTC->ALMHOUR;
pstcAlarmTime->u8Week = M0P_RTC->ALMWEEK;
enRet = Ok;
return enRet; |