ls1x-master-v0.4/public/ls1x_rtc.c

82 lines
2.0 KiB
C
Raw Normal View History

2024-11-27 15:39:05 +08:00
#include"ls1x.h"
#include"ls1x_rtc.h"
/***********************************************************************
function: <EFBFBD><EFBFBD>ȡrtcʱ<EFBFBD><EFBFBD>
@param : Rtime rtc<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
@other : <EFBFBD><EFBFBD>
@return : void
@auther : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@time : 2020<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>9<EFBFBD><EFBFBD>
***********************************************************************/
void Rtc_Read(tsRtcTime *Rtime)
{
INT32U Rtc_time1 = 0;
INT32U Rtc_time2 = 0;
Rtc_time1 = RTC_RTC1;
Rtc_time2 = RTC_RTC0;
Rtime->year = (Rtc_time1 & 0xFE00) >> 9;
Rtime->mon = (Rtc_time1 & 0x1E0) >> 5;
Rtime->day = (Rtc_time1 & 0x1F);
Rtime->hour = (Rtc_time2 & 0x1F0000) >> 16;
Rtime->min = (Rtc_time2 & 0xFC00) >> 10;
Rtime->sec = (Rtc_time2 & 0x3F0) >> 4;
}
/***********************************************************************
function: д<EFBFBD><EFBFBD>rtcʱ<EFBFBD><EFBFBD>
@param : Wtime rtcд<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
@other : <EFBFBD><EFBFBD>
@return : void
@auther : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@time : 2020<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>9<EFBFBD><EFBFBD>
***********************************************************************/
void Rtc_Write(tsRtcTime *Wtime)
{
if(((Wtime->mon) > 12) || ((Wtime->mon) <= 0))
Wtime->mon = 1;
if(((Wtime->day) > 31) || ((Wtime->day) <= 0))
Wtime->day = 1;
RTC_FREQ = (0x800 << 16) ; // 32768Hz -> 16Hz
RTC_RTC0 = (((Wtime->hour) % 24) << 16) | (((Wtime->min) % 60) << 10) | (((Wtime->sec) % 60) << 4) | (((Wtime->week) % 100) << 0); // <20><><EFBFBD>ó<EFBFBD>ʼʱ<CABC><CAB1>ʱ<EFBFBD><CAB1><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>
RTC_RTC1 = ((Wtime->year) << 9) | (((Wtime->mon) % 13) << 5) | (((Wtime->day) % 32) << 0); // <20><><EFBFBD>ó<EFBFBD>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD>¡<EFBFBD><C2A1><EFBFBD>
RTC_CFG = 0x80000000;
}
/***********************************************************************
function: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>RTC
@param : direction <EFBFBD>ж<EFBFBD><EFBFBD>Ƕ<EFBFBD>ȡRTC,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>дRTC
time <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
@other : <EFBFBD><EFBFBD>
@return : void
@auther : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@time : 2020<EFBFBD><EFBFBD>4<EFBFBD><EFBFBD>9<EFBFBD><EFBFBD>
***********************************************************************/
void RtcUpdateData(INT8U direction, tsRtcTime *time)
{
INT32U ret;
if(direction) //<2F><>
{
Rtc_Read(time);
}
else //д
{
Rtc_Write(time);
}
}