完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
简单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● |
|
相关推荐
1个回答
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
飞凌嵌入式-ELFBOARD 硬件知识分享-ELF 2电源电路讲解
563 浏览 0 评论
1515 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-mfgtools烧录流程介绍之烧写所需镜像
1357 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-mfgtools烧录流程之烧写方法
793 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-内核编译之初次编译
1239 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 20:43 , Processed in 2.743194 second(s), Total 71, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号