rt-thread/bsp/essemi/es8p508x/libraries/Library/Source/lib_rtc.c

1907 lines
40 KiB
C
Raw Normal View History

2019-11-07 10:00:14 +08:00
/*********************************************************
*Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd.
*<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>: lib_rtc.c
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: Liut
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: V1.00
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: 2017/07/14
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: RTCģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*<EFBFBD><EFBFBD> ע: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HRSDK-GDB-ES8P508 V1.1
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>κη<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD>
**********************************************************/
#include "lib_rtc.h"
#include "lib_scu.h"
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_Init
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵʱʱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>CLKx:RTCʱ<EFBFBD><EFBFBD>Դѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>HOURx<EFBFBD><EFBFBD>12Сʱ/24Сʱ<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
void RTC_Init(RTC_TYPE_CLKS CLKx,RTC_TYPE_TIME HOURx)
{
uint32_t flag;
if(CLKx == RTC_LOSC )
{
uint32_t Prot_Temp;
Prot_Temp = SCU->PROT.PROT;
if(Prot_Temp != 0) //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SCU_RegUnLock(); //<2F><><EFBFBD><EFBFBD>
SCU_XTAL_Enable(); //ʹ<><CAB9><EFBFBD>ⲿ32kHZ
while(SCU_XTALReadyFlag() != SET); //<2F>ȴ<EFBFBD>ʱ<EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>
if(Prot_Temp != 0)
SCU_RegLock(); //<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
RTC->CON.PON = 0; // <20><><EFBFBD>ʹ<E3A3AC><CAB9>RTC
RTC->CON.HSWI = HOURx; // 24Сʱģʽ
RTC->CON.CLKS = CLKx; // ʱ<><CAB1>Դѡ<D4B4><D1A1>32768Hz
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_StartRead
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵʱʱ<EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
void RTC_StartRead(void)
{
RTC->CON.TMWR = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>
RTC->CON.TMUP = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while (RTC->CON.TMUP == 1); //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadHourmode
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡСʱģʽ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>Сʱģʽ
***************************************************************/
uint32_t RTC_ReadHourmode(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
result = RTC->CON.HSWI;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadSecond
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
uint32_t RTC_ReadSecond(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->HMS.SEC & (uint32_t)0x01) * 1);
result += (((RTC->HMS.SEC >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->HMS.SEC >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->HMS.SEC >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->HMS.SEC >> 4) & (uint32_t)0x01) * 10);
result += (((RTC->HMS.SEC >> 5) & (uint32_t)0x01) * 20);
result += (((RTC->HMS.SEC >> 6) & (uint32_t)0x01) * 40);
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadMinute
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ķ<EFBFBD>
***************************************************************/
uint32_t RTC_ReadMinute(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->HMS.MIN & (uint32_t)0x01) * 1);
result += (((RTC->HMS.MIN >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->HMS.MIN >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->HMS.MIN >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->HMS.MIN >> 4) & (uint32_t)0x01) * 10);
result += (((RTC->HMS.MIN >> 5) & (uint32_t)0x01) * 20);
result += (((RTC->HMS.MIN >> 6) & (uint32_t)0x01) * 40);
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadHour
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡСʱ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>Сʱ
***************************************************************/
uint32_t RTC_ReadHour(uint32_t *meridiem)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->HMS.HOUR & (uint32_t)0x01) * 1);
result += (((RTC->HMS.HOUR >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->HMS.HOUR >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->HMS.HOUR >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->HMS.HOUR >> 4) & (uint32_t)0x01) * 10);
if(RTC_ReadHourmode() == RTC_HOUR24) //24Сʱģʽ<C4A3><CABD>20Сʱ
{
result += (((RTC->HMS.HOUR >> 5) & (uint32_t)0x01) * 20);
}
else //12Сʱģʽ<C4A3><CABD>1 PM,0 AM
{
*meridiem = (((RTC->HMS.HOUR >> 5) & (uint32_t)0x01));
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadDay
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
uint32_t RTC_ReadDay(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->YMDW.DAY & (uint32_t)0x01) * 1);
result += (((RTC->YMDW.DAY >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->YMDW.DAY >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->YMDW.DAY >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->YMDW.DAY >> 4) & (uint32_t)0x01) * 10);
result += (((RTC->YMDW.DAY >> 5) & (uint32_t)0x01) * 20);
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadMonth
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
uint32_t RTC_ReadMonth(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->YMDW.MON & (uint32_t)0x01) * 1);
result += (((RTC->YMDW.MON >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->YMDW.MON >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->YMDW.MON >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->YMDW.MON >> 4) & (uint32_t)0x01) * 10);
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadYear
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
uint32_t RTC_ReadYear(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->YMDW.YEAR & (uint32_t)0x01) * 1);
result += (((RTC->YMDW.YEAR >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->YMDW.YEAR >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->YMDW.YEAR >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->YMDW.YEAR >> 4) & (uint32_t)0x01) * 10);
result += (((RTC->YMDW.YEAR >> 5) & (uint32_t)0x01) * 20);
result += (((RTC->YMDW.YEAR >> 6) & (uint32_t)0x01) * 40);
result += (((RTC->YMDW.YEAR >> 7) & (uint32_t)0x01) * 80);
result += 2000;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadWeek
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
uint32_t RTC_ReadWeek(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
switch(RTC->YMDW.WEEK)
{
case 0x00: result = 0;break;
case 0x01: result = 1;break;
case 0x02: result = 2;break;
case 0x03: result = 3;break;
case 0x04: result = 4;break;
case 0x05: result = 5;break;
case 0x06: result = 6;break;
default: result = 0;break;
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_StartRead
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵʱʱ<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
void RTC_StartWrite(void)
{
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC->CON.TMWR = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
RTC->CON.TMUP = 1; // <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
while (RTC->CON.TMUP == 1); //<2F>ȴ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteSecond
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>second: <EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteSecond(uint32_t second)
{
uint32_t flag = 0;
uint32_t sec_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (second >= 60)
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if (second >= 40)
{
sec_buf |= (uint32_t)1<<6;
second -= 40;
}
else
{
sec_buf &= ~(uint32_t)1<<6;
}
if (second >= 20)
{
sec_buf |= (uint32_t)1<<5;
second -= 20;
}
else
{
sec_buf &= ~(uint32_t)1<<5;
}
if (second >= 10)
{
sec_buf |= (uint32_t)1<<4;
second -= 10;
}
else
{
sec_buf &= ~(uint32_t)1<<4;
}
if (second >= 8)
{
sec_buf |= (uint32_t)1<<3;
second -= 8;
}
else
{
sec_buf &= ~(uint32_t)1<<3;
}
if (second >= 4)
{
sec_buf |= (uint32_t)1<<2;
second -= 4;
}
else
{
sec_buf &= ~(uint32_t)1<<2;
}
if (second >= 2)
{
sec_buf |= (uint32_t)1<<1;
second -= 2;
}
else
{
sec_buf &= ~(uint32_t)1<<1;
}
if (second >= 1)
{
sec_buf |= (uint32_t)1;
second -= 1;
}
else
{
sec_buf &= ~(uint32_t)1;
}
RTC->HMS.SEC = sec_buf;
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartWrite();
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteMinute
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>minute: <EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteMinute(uint32_t minute)
{
uint32_t flag;
uint32_t min_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (minute >= 60)
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if (minute >= 40)
{
min_buf |= (uint32_t)1<<6;
minute -= 40;
}
else
{
min_buf &= ~(uint32_t)1<<6;
}
if (minute >= 20)
{
min_buf |= (uint32_t)1<<5;
minute -= 20;
}
else
{
min_buf &= ~(uint32_t)1<<5;
}
if (minute >= 10)
{
min_buf |= (uint32_t)1<<4;
minute -= 10;
}
else
{
min_buf &= ~(uint32_t)1<<4;
}
if (minute >= 8)
{
min_buf |= (uint32_t)1<<3;
minute -= 8;
}
else
{
min_buf &= ~(uint32_t)1<<3;
}
if (minute >= 4)
{
min_buf |= (uint32_t)1<<2;
minute -= 4;
}
else
{
min_buf &= ~(uint32_t)1<<2;
}
if (minute >= 2)
{
min_buf |= (uint32_t)1<<1;
minute -= 2;
}
else
{
min_buf &= ~(uint32_t)1<<1;
}
if (minute >= 1)
{
min_buf |= (uint32_t)1;
minute -= 1;
}
else
{
min_buf &= ~(uint32_t)1;
}
RTC->HMS.MIN = min_buf;
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartWrite();
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteHour
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>ʱ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>hour: ʱ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteHour(uint32_t hour, uint32_t meridiem)
{
uint32_t flag,mode;
uint32_t hour_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (hour >= 24)
return ERROR;
mode = RTC_ReadHourmode();
if(mode == RTC_HOUR12 && hour > 12) //12Сʱģʽ<C4A3><CABD><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>12Сʱ
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if(mode == RTC_HOUR24)
{
if (hour >= 20)
{
hour_buf |= (uint32_t)1<<5;
hour -= 20;
}
else
{
hour_buf &= ~((uint32_t)1<<5);
}
}
else
{
if(meridiem == 1)
hour_buf |= (uint32_t)1<<5;
else
hour_buf &= ~((uint32_t)1<<5);
}
if (hour >= 10)
{
hour_buf |= (uint32_t)1<<4;
hour -= 10;
}
else
{
hour_buf &= ~((uint32_t)1<<4);
}
if (hour >= 8)
{
hour_buf |= (uint32_t)1<<3;
hour -= 8;
}
else
{
hour_buf &= ~((uint32_t)1<<3);
}
if (hour >= 4)
{
hour_buf |= (uint32_t)1<<2;
hour -= 4;
}
else
{
hour_buf &= ~((uint32_t)1<<2);
}
if (hour >= 2)
{
hour_buf |= (uint32_t)1<<1;
hour -= 2;
}
else
{
hour_buf &= ~((uint32_t)1<<1);
}
if (hour >= 1)
{
hour_buf |= (uint32_t)1;
hour -= 1;
}
else
{
hour_buf &= ~(uint32_t)1;
}
RTC->HMS.HOUR = hour_buf;
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartWrite();
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteDay
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>day: <EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteDay(uint32_t day)
{
uint32_t flag;
uint32_t day_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if ((day == 0) || (day >= 32))
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if (day >= 20)
{
day_buf |= (uint32_t)1<<5;
day -= 20;
}
else
{
day_buf &= ~((uint32_t)1<<5);
}
if (day >= 10)
{
day_buf |= (uint32_t)1<<4;
day -= 10;
}
else
{
day_buf &= ~((uint32_t)1<<4);
}
if (day >= 8)
{
day_buf |= (uint32_t)1<<3;
day -= 8;
}
else
{
day_buf &= ~((uint32_t)1<<3);
}
if (day >= 4)
{
day_buf |= (uint32_t)1<<2;
day -= 4;
}
else
{
day_buf &= ~((uint32_t)1<<2);
}
if (day >= 2)
{
day_buf |= (uint32_t)1<<1;
day -= 2;
}
else
{
day_buf &= ~((uint32_t)1<<1);
}
if (day >= 1)
{
day_buf |= (uint32_t)1;
day -= 1;
}
else
{
day_buf &= ~(uint32_t)1;
}
RTC->YMDW.DAY = day_buf;
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartWrite();
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteMonth
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>month: <EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteMonth(uint32_t month)
{
uint32_t flag;
uint32_t month_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if ((month == 0) || (month >= 13))
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if (month >= 10)
{
month_buf |= (uint32_t)1<<4;
month -= 10;
}
else
{
month_buf &= ~((uint32_t)1<<4);
}
if (month >= 8)
{
month_buf |= (uint32_t)1<<3;
month -= 8;
}
else
{
month_buf &= ~((uint32_t)1<<3);
}
if (month >= 4)
{
month_buf |= (uint32_t)1<<2;
month -= 4;
}
else
{
month_buf &= ~((uint32_t)1<<2);
}
if (month >= 2)
{
month_buf |= (uint32_t)1<<1;
month -= 2;
}
else
{
month_buf &= ~((uint32_t)1<<1);
}
if (month >= 1)
{
month_buf |= (uint32_t)1;
month -= 1;
}
else
{
month_buf &= ~(uint32_t)1;
}
RTC->YMDW.MON = month_buf;
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartWrite();
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteYear
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>year: <EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteYear(uint32_t year)
{
uint32_t flag;
uint32_t year_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if ((year < 2000) || (year > 2099))
return ERROR;
/* <20><>ת<EFBFBD><D7AA> */
year -= 2000;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if (year >= 80)
{
year_buf |= (uint32_t)1<<7;
year -= 80;
}
else
{
year_buf &= ~((uint32_t)1<<7);
}
if (year >= 40)
{
year_buf |= (uint32_t)1<<6;
year -= 40;
}
else
{
year_buf &= ~((uint32_t)1<<6);
}
if (year >= 20)
{
year_buf |= (uint32_t)1<<5;
year -= 20;
}
else
{
year_buf &= ~((uint32_t)1<<5);
}
if (year >= 10)
{
year_buf |= (uint32_t)1<<4;
year -= 10;
}
else
{
year_buf &= ~((uint32_t)1<<4);
}
if (year >= 8)
{
year_buf |= (uint32_t)1<<3;
year -= 8;
}
else
{
year_buf &= ~((uint32_t)1<<3);
}
if (year >= 4)
{
year_buf |= (uint32_t)1<<2;
year -= 4;
}
else
{
year_buf &= ~((uint32_t)1<<2);
}
if (year >= 2)
{
year_buf |= (uint32_t)1<<1;
year -= 2;
}
else
{
year_buf &= ~((uint32_t)1<<1);
}
if (year >= 1)
{
year_buf |= (uint32_t)1;
year -= 1;
}
else
{
year_buf &= ~(uint32_t)1;
}
RTC->YMDW.YEAR = year_buf;
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartWrite();
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteWeek
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>week: <EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>0-6<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteWeek(uint32_t week)
{
uint32_t flag;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (week > 6)
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
RTC->YMDW.WEEK = week;
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC->CON.TMWR = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д
RTC->CON.TMUP = 1; // <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
while (RTC->CON.TMUP == 1);
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadWeekAlarmMinute
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ķ<EFBFBD>
***************************************************************/
uint32_t RTC_ReadWeekAlarmMinute(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->WA.WM & (uint32_t)0x01) * 1);
result += (((RTC->WA.WM >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->WA.WM >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->WA.WM >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->WA.WM >> 4) & (uint32_t)0x01) * 10);
result += (((RTC->WA.WM >> 5) & (uint32_t)0x01) * 20);
result += (((RTC->WA.WM >> 6) & (uint32_t)0x01) * 40);
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadWeekAlarmHour
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡСʱ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>Сʱ
***************************************************************/
uint32_t RTC_ReadWeekAlarmHour(uint32_t *meridiem)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->WA.WH & (uint32_t)0x01) * 1);
result += (((RTC->WA.WH >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->WA.WH >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->WA.WH >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->WA.WH >> 4) & (uint32_t)0x01) * 10);
if(RTC_ReadHourmode() == RTC_HOUR24) //24Сʱģʽ<C4A3><CABD>20Сʱ
{
result += (((RTC->WA.WH >> 5) & (uint32_t)0x01) * 20);
}
else //12Сʱģʽ<C4A3><CABD>1 PM,0 AM
{
*meridiem = (((RTC->WA.WH >> 5) & (uint32_t)0x01));
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadWeekAlarmWeek
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
uint32_t RTC_ReadWeekAlarmWeek(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
switch(RTC->WA.WW)
{
case 0x00: result = 0;break;
case 0x01: result = 1;break;
case 0x02: result = 2;break;
case 0x03: result = 3;break;
case 0x04: result = 4;break;
case 0x05: result = 5;break;
case 0x06: result = 6;break;
default: result = 0;break;
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadDayAlarmMinute
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
uint32_t RTC_ReadDayAlarmMinute(void)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->DA.DM & (uint32_t)0x01) * 1);
result += (((RTC->DA.DM >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->DA.DM >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->DA.DM >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->DA.DM >> 4) & (uint32_t)0x01) * 10);
result += (((RTC->DA.DM >> 5) & (uint32_t)0x01) * 20);
result += (((RTC->DA.DM >> 6) & (uint32_t)0x01) * 40);
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ReadDaykAlarmHour
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡСʱ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>Сʱ
***************************************************************/
uint32_t RTC_ReadDayAlarmHour(uint32_t *meridiem)
{
uint32_t flag;
uint32_t result;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
RTC_StartRead();
/* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
result = ((RTC->DA.DH & (uint32_t)0x01) * 1);
result += (((RTC->DA.DH >> 1) & (uint32_t)0x01) * 2);
result += (((RTC->DA.DH >> 2) & (uint32_t)0x01) * 4);
result += (((RTC->DA.DH >> 3) & (uint32_t)0x01) * 8);
result += (((RTC->DA.DH >> 4) & (uint32_t)0x01) * 10);
if(RTC_ReadHourmode() == RTC_HOUR24) //24Сʱģʽ<C4A3><CABD>20Сʱ
{
result += (((RTC->DA.DH >> 5) & (uint32_t)0x01) * 20);
}
else //12Сʱģʽ<C4A3><CABD>1 PM,0 AM
{
*meridiem = (((RTC->DA.DH >> 5) & (uint32_t)0x01));
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteWeekAlarmMinute
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ķ<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>minute: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteWeekAlarmMinute(uint32_t minute)
{
uint32_t flag;
uint32_t minute_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (minute >= 60)
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if (minute >= 40)
{
minute_buf |= (uint32_t)1<<6;
minute -= 40;
}
else
{
minute_buf &= ~(uint32_t)1<<6;
}
if (minute >= 20)
{
minute_buf |= (uint32_t)1<<5;
minute -= 20;
}
else
{
minute_buf &= ~(uint32_t)1<<5;
}
if (minute >= 10)
{
minute_buf |= (uint32_t)1<<4;
minute -= 10;
}
else
{
minute_buf &= ~(uint32_t)1<<4;
}
if (minute >= 8)
{
minute_buf |= (uint32_t)1<<3;
minute -= 8;
}
else
{
minute_buf &= ~(uint32_t)1<<3;
}
if (minute >= 4)
{
minute_buf |= (uint32_t)1<<2;
minute -= 4;
}
else
{
minute_buf &= ~(uint32_t)1<<2;
}
if (minute >= 2)
{
minute_buf |= (uint32_t)1<<1;
minute -= 2;
}
else
{
minute_buf &= ~(uint32_t)1<<1;
}
if (minute >= 1)
{
minute_buf |= (uint32_t)1;
minute -= 1;
}
else
{
minute_buf &= ~(uint32_t)1;
}
RTC->WA.WM = minute_buf;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteWeekAlarmHour
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>Сʱ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>hour: Сʱ
meridiem<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>12Сʱģʽʱ<EFBFBD><EFBFBD>Ч)
0 AM
1 PM
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteWeekAlarmHour(uint32_t hour, uint32_t meridiem)
{
uint32_t flag,mode;
uint32_t hour_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (hour >= 24)
return ERROR;
mode = RTC_ReadHourmode();
if(mode == RTC_HOUR12 && hour > 12) //12Сʱģʽ<C4A3><CABD><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>12Сʱ
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if(mode == RTC_HOUR24)
{
if (hour >= 20)
{
hour_buf |= (uint32_t)1<<5;
hour -= 20;
}
else
{
hour_buf &= ~((uint32_t)1<<5);
}
}
else
{
if(meridiem == 1)
hour_buf |= (uint32_t)1<<5;
else
hour_buf &= ~((uint32_t)1<<5);
}
if (hour >= 10)
{
hour_buf |= (uint32_t)1<<4;
hour -= 10;
}
else
{
hour_buf &= ~((uint32_t)1<<4);
}
if (hour >= 8)
{
hour_buf |= (uint32_t)1<<3;
hour -= 8;
}
else
{
hour_buf &= ~((uint32_t)1<<3);
}
if (hour >= 4)
{
hour_buf |= (uint32_t)1<<2;
hour -= 4;
}
else
{
hour_buf &= ~((uint32_t)1<<2);
}
if (hour >= 2)
{
hour_buf |= (uint32_t)1<<1;
hour -= 2;
}
else
{
hour_buf &= ~((uint32_t)1<<1);
}
if (hour >= 1)
{
hour_buf |= (uint32_t)1;
hour -= 1;
}
else
{
hour_buf &= ~(uint32_t)1;
}
RTC->WA.WH = hour_buf;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteWeekAlarmWeek
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>week: <EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>0-6<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteWeekAlarmWeek(uint32_t week)
{
uint32_t flag;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (week > 6)
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
RTC->WA.WW = week;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteDayAlarmMinute
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ķ<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>minute: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteDayAlarmMinute(uint32_t minute)
{
uint32_t flag,minute_buf;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (minute >= 60)
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if (minute >= 40)
{
minute_buf |= (uint32_t)1<<6;
minute -= 40;
}
else
{
minute_buf &= ~(uint32_t)1<<6;
}
if (minute >= 20)
{
minute_buf |= (uint32_t)1<<5;
minute -= 20;
}
else
{
minute_buf &= ~(uint32_t)1<<5;
}
if (minute >= 10)
{
minute_buf |= (uint32_t)1<<4;
minute -= 10;
}
else
{
minute_buf &= ~(uint32_t)1<<4;
}
if (minute >= 8)
{
minute_buf |= (uint32_t)1<<3;
minute -= 8;
}
else
{
minute_buf &= ~(uint32_t)1<<3;
}
if (minute >= 4)
{
minute_buf |= (uint32_t)1<<2;
minute -= 4;
}
else
{
minute_buf &= ~(uint32_t)1<<2;
}
if (minute >= 2)
{
minute_buf |= (uint32_t)1<<1;
minute -= 2;
}
else
{
minute_buf &= ~(uint32_t)1<<1;
}
if (minute >= 1)
{
minute_buf |= (uint32_t)1;
minute -= 1;
}
else
{
minute_buf &= ~(uint32_t)1;
}
RTC->DA.DM = minute_buf;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_WriteDayAlarmHour
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>Сʱ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>hour: Сʱ
meridiem<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>12Сʱģʽʱ<EFBFBD><EFBFBD>Ч)
0 AM
1 PM
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
ErrorStatus RTC_WriteDayAlarmHour(uint32_t hour, uint32_t meridiem)
{
uint32_t flag,mode;
uint32_t hour_buf = 0;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
if (hour >= 24)
return ERROR;
mode = RTC_ReadHourmode();
if(mode == RTC_HOUR12 && hour > 12) //12Сʱģʽ<C4A3><CABD><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>12Сʱ
return ERROR;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
if(mode == RTC_HOUR24)
{
if (hour >= 20)
{
hour_buf |= (uint32_t)1<<5;
hour -= 20;
}
else
{
hour_buf &= ~((uint32_t)1<<5);
}
}
else
{
if(meridiem == 1)
hour_buf |= (uint32_t)1<<5;
else
hour_buf &= ~((uint32_t)1<<5);
}
if (hour >= 10)
{
hour_buf |= (uint32_t)1<<4;
hour -= 10;
}
else
{
hour_buf &= ~((uint32_t)1<<4);
}
if (hour >= 8)
{
hour_buf |= (uint32_t)1<<3;
hour -= 8;
}
else
{
hour_buf &= ~((uint32_t)1<<3);
}
if (hour >= 4)
{
hour_buf |= (uint32_t)1<<2;
hour -= 4;
}
else
{
hour_buf &= ~((uint32_t)1<<2);
}
if (hour >= 2)
{
hour_buf |= (uint32_t)1<<1;
hour -= 2;
}
else
{
hour_buf &= ~((uint32_t)1<<1);
}
if (hour >= 1)
{
hour_buf |= (uint32_t)1;
hour -= 1;
}
else
{
hour_buf &= ~(uint32_t)1;
}
RTC->DA.DH = hour_buf;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return SUCCESS;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_InterruptEnable
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>ʵʱʱ<EFBFBD>ӵ<EFBFBD>ijЩ<EFBFBD>ж<EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>src: ʵʱʱ<EFBFBD>ӵ<EFBFBD><EFBFBD>ж<EFBFBD>Դ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
void RTC_InterruptEnable(RTC_Interrupt_Source src)
{
uint32_t flag;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
switch (src)
{
case RTC_Interrupt_Source_Second:
RTC->IE.SCDIE = 1;
break;
case RTC_Interrupt_Source_Minute:
RTC->IE.MINIE = 1;
break;
case RTC_Interrupt_Source_Hour:
RTC->IE.HORIE = 1;
break;
case RTC_Interrupt_Source_Day:
RTC->IE.DAYIE = 1;
break;
case RTC_Interrupt_Source_Month:
RTC->IE.MONIE = 1;
break;
case RTC_Interrupt_Source_DayALE:
RTC->IE.DALE = 1;
break;
case RTC_Interrupt_Source_WeekALE:
RTC->IE.WALE = 1;
break;
default:
break;
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
NVIC->ISER[0] |= (1 << 20); // ʹ<><CAB9>NVIC<49>ж<EFBFBD>
return;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_InterruptDisable
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵʱʱ<EFBFBD>ӵ<EFBFBD>ijЩ<EFBFBD>ж<EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>src: ʵʱʱ<EFBFBD>ӵ<EFBFBD><EFBFBD>ж<EFBFBD>Դ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
void RTC_InterruptDisable(RTC_Interrupt_Source src)
{
uint32_t flag;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
/* <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ֵ */
switch (src)
{
case RTC_Interrupt_Source_Second:
RTC->IE.SCDIE = 0;
break;
case RTC_Interrupt_Source_Minute:
RTC->IE.MINIE = 0;
break;
case RTC_Interrupt_Source_Hour:
RTC->IE.HORIE = 0;
break;
case RTC_Interrupt_Source_Day:
RTC->IE.DAYIE = 0;
break;
case RTC_Interrupt_Source_Month:
RTC->IE.MONIE = 0;
break;
case RTC_Interrupt_Source_DayALE:
RTC->IE.DALE = 0;
break;
case RTC_Interrupt_Source_WeekALE:
RTC->IE.WALE = 0;
break;
default:
break;
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_GetITStatus
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʵʱʱ<EFBFBD>ӵ<EFBFBD>ijЩ<EFBFBD>ж<EFBFBD>״̬
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>src: ʵʱʱ<EFBFBD>ӵ<EFBFBD><EFBFBD>ж<EFBFBD>Դ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>жϱ<EFBFBD>־
***************************************************************/
ITStatus RTC_GetITStatus(RTC_Interrupt_Source src)
{
ITStatus result = RESET;
switch (src)
{
case RTC_Interrupt_Source_Second:
if(RTC->IE.SCDIE)
result = SET;
break;
case RTC_Interrupt_Source_Minute:
if(RTC->IE.MINIE)
result = SET;
break;
case RTC_Interrupt_Source_Hour:
if(RTC->IE.HORIE)
result = SET;
break;
case RTC_Interrupt_Source_Day:
if(RTC->IE.DAYIE)
result = SET;
break;
case RTC_Interrupt_Source_Month:
if(RTC->IE.MONIE)
result = SET;
break;
case RTC_Interrupt_Source_DayALE:
if(RTC->IE.DALE)
result = SET;
break;
case RTC_Interrupt_Source_WeekALE:
if(RTC->IE.WALE)
result = SET;
break;
default:
result = RESET;
break;
}
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_GetFlagStatus
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʵʱʱ<EFBFBD>ӵ<EFBFBD>ijЩ<EFBFBD>жϱ<EFBFBD>־
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>src: ʵʱʱ<EFBFBD>ӵ<EFBFBD><EFBFBD>ж<EFBFBD>Դ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>жϱ<EFBFBD>־
***************************************************************/
FlagStatus RTC_GetFlagStatus(RTC_Interrupt_Source src)
{
FlagStatus result = RESET;
switch (src)
{
case RTC_Interrupt_Source_Second:
if(RTC->IF.SCDIF)
result = SET;
break;
case RTC_Interrupt_Source_Minute:
if(RTC->IF.MINIF)
result = SET;
break;
case RTC_Interrupt_Source_Hour:
if(RTC->IF.HORIF)
result = SET;
break;
case RTC_Interrupt_Source_Day:
if(RTC->IF.DAYIF)
result = SET;
break;
case RTC_Interrupt_Source_Month:
if(RTC->IF.MONIF)
result = SET;
break;
case RTC_Interrupt_Source_DayALE:
if(RTC->IF.DAFG)
result = SET;
break;
case RTC_Interrupt_Source_WeekALE:
if(RTC->IF.WAFG)
result = SET;
break;
default:
result = RESET;
break;
}
return result;
}
/***************************************************************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC_ClearITPendingBit
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϱ<EFBFBD>־λ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>src: ʵʱʱ<EFBFBD>ӵ<EFBFBD><EFBFBD>ж<EFBFBD>Դ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************/
void RTC_ClearITPendingBit(RTC_Interrupt_Source src)
{
uint32_t flag;
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
flag = RTC->WP.WP;
if (flag == 0x00000000)
RTC->WP.WP = 0x55AAAA55;
switch (src)
{
case RTC_Interrupt_Source_Second:
RTC->IF.Word = RTC_Interrupt_Source_Second;
break;
case RTC_Interrupt_Source_Minute:
RTC->IF.Word = RTC_Interrupt_Source_Minute;
break;
case RTC_Interrupt_Source_Hour:
RTC->IF.Word = RTC_Interrupt_Source_Hour;
break;
case RTC_Interrupt_Source_Day:
RTC->IF.Word = RTC_Interrupt_Source_Day;
break;
case RTC_Interrupt_Source_Month:
RTC->IF.Word = RTC_Interrupt_Source_Month;
break;
case RTC_Interrupt_Source_DayALE:
RTC->IF.Word = RTC_Interrupt_Source_DayALE;
break;
case RTC_Interrupt_Source_WeekALE:
RTC->IF.Word = RTC_Interrupt_Source_WeekALE;
break;
default:
break;
}
/* <20><><EFBFBD><EFBFBD>RTCд<43><D0B4><EFBFBD><EFBFBD> */
if (flag == 0x00000000)
RTC->WP.WP = 0x00000000;
return;
}
/*************************END OF FILE**********************/