简单RTC应用,获取RTC时间,以及设置时间
void RTC_Ctrl_Set(U8 enable) //bit位使能
{
if (FALSE == enable)
{
RTCCON &= ~(1 << 0);
}
else
{
RTCCON |= (1 << 0);
}
}
void Get_RTC_
time(RTC_Time_Typedef *time)
{//获取RTC时钟的各个部分
time->second = BCDSEC;
time->minute = BCDMIN;
time->hour = BCDHOUR;
time->date = BCDDATE; //星期
time->day = BCDDAY;
time->month = BCDMON;
time->year = BCDYEAR;
}
void Set_RTC_Time(RTC_Time_Typedef time)
{//设置RTC时间
RTC_Ctrl_Set(TRUE);
BCDSEC = time.second;
BCDMIN = time.minute;
BCDHOUR = time.hour;
BCDDATE = time.date; //ÐÇÆÚ
BCDDAY = time.day;
BCDMON = time.month;
BCDYEAR = time.year;
RTC_Ctrl_Set(FALSE);
}
头文件中的相关定义
typedef struct
{
U8 second;
U8 minute;
U8 hour;
U8 date;
U8 day;
U8 month;
U8 year;
}RTC_Time_Typedef;
extern void RTC_Ctrl_Set(U8 enable); //设置使能
extern void Get_RTC_Time(RTC_Time_Typedef *time); //获取时间
extern void Set_RTC_Time(RTC_Time_Typedef time); //设置时间
typedef.h的相关定义
<使用方便>
#define U32 unsigned int
#define U16 unsigned short
#define S32 int
#define S16 short int
#define U8 unsigned char
#define S8 char
#define TRUE 1
#define FALSE 0
寄存器配置
#define RTCCON (*(volatile unsigned short *)0x57000040)
#define TICNT0 (*(volatile unsigned char *)0x57000044)
#define TICNT1 (*(volatile unsigned char *)0x5700004c)
#define TICNT2 (*(volatile unsigned int *)0x57000048)
#define RTCALM (*(volatile unsigned char *)0x57000050)
#define ALMSEC (*(volatile unsigned char *)0x57000054)
#define ALMMIN (*(volatile unsigned char *)0x57000058)
#define ALMHOUR (*(volatile unsigned char *)0x5700005c)
#define ALMDATE (*(volatile unsigned char *)0x57000060)
#define ALMMON (*(volatile unsigned char *)0x57000064)
#define ALMYEAR (*(volatile unsigned char *)0x57000068)
#define RTCRST (*(volatile unsigned char *)0x5700006c)
#define BCDSEC (*(volatile unsigned char *)0x57000070)
#define BCDMIN (*(volatile unsigned char *)0x57000074)
#define BCDHOUR (*(volatile unsigned char *)0x57000078)
#define BCDDATE (*(volatile unsigned char *)0x5700007c)
#define BCDDAY (*(volatile unsigned char *)0x57000080)
#define BCDMON (*(volatile unsigned char *)0x57000084)
#define BCDYEAR (*(volatile unsigned char *)0x57000088)
#define TICKCNT (*(volatile unsigned *)0x57000090)
原作者:●Jane●
0
使用方便>