完善资料让更多小伙伴认识你,还能领取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个回答
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
860 浏览 1 评论
飞凌嵌入式ElfBoard ELF 1板卡-spi编程示例之spi编写程序
526 浏览 0 评论
飞凌嵌入式-ELFBOARD 4.3吋电容触摸液晶模块简介第三期 :机械机构说明
691 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-i2c与从设备通讯编程示例之开发板测试
1370 浏览 0 评论
ubuntu ping 开发板存在严重的丢包情况,请问该怎么解决?
2517 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-9 07:47 , Processed in 0.647444 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号