|
|
本帖最后由 luozewei 于 2026-4-12 16:53 编辑
T5L有内置RTC寄存器的,位置在扩展data区,操作需要RTCSEL来指定的。
sfr RTCDAT = 0xCF; //RTC数据寄存器
sfr RTCSEL = 0xCE; //RTC选择寄存器
sfr IEN3 = 0xD1; //.5 ERTC RTC中断使能
typedef enum {
RTASS = 0x00, //Alarm
RTAS = 0x01,
RTAM = 0x02,
RTAH = 0x03,
RTCC = 0x04,
UNDEFINED = 0x05,
RTCSS = 0x06, //Register
RTCS = 0x07,
RTCM = 0x08,
RTCH = 0x09,
RTCD0 = 0x0A, //day
RTCD1 = 0x0B,
}RTC_SEL;
typedef enum {
RTCE = 0x01, //RTC on/off
RTCIF = 0x02, //RTC interrupt
RTCWE = 0x04, //write enable
RTCRE = 0x08, //read enable
HCE = 0x10, //hour alm interrupt enable
MCE = 0x20, //min alm interrupt enable
SCE = 0x40, //sec alm interrupt enable
SSCE = 0x80, //ms alm interrupt enable
}RTCC_SET;
typedef struct{
uint8_t hour;
uint8_t min;
uint8_t sec;
uint8_t rec;
}RTC_TimeTypeDef;
xdata RTC_TimeTypeDef realTime;
void RTC_Init(void)
{
RTCSEL = RTCC; //选择扩展data区RTCC设置寄存器
RTCDAT = RTCE | RTCWE; //设置写模式
RTCSEL = RTCS; //选择RTCS秒寄存器
RTCDAT = 00; //RTCS值归0秒
RTCSEL = RTCM; //选择RTCM分寄存器
RTCDAT = 00; //RTCM值归0分
RTCSEL = RTCH; //选择RTCH小时寄存器
RTCDAT = 12; //RTCH设置12点
RTCSEL = RTCD0; //选择RTCH天寄存器
RTCDAT = 0;
RTCSEL = RTASS; //RTCH设置秒中断时刻点
RTCDAT = 255;
RTCSEL = RTCC;
RTCDAT &= ~RTCWE; //RTC关闭写模式
RTCDAT |= SSCE; //RTC设置秒中断IE
RTCSEL = RTCC; //选择RTCC设置寄存器
RTCDAT |= RTCRE; //设置读模式
RTCSEL = RTCS; //以下RTC 秒,分,时,寄存器读出
realTime.sec = RTCDAT;
RTCSEL = RTCM;
realTime.min = RTCDAT;
RTCSEL = RTCH;
realTime.hour = RTCDAT;
Write_Dgus((uint8_t*)&realTime, 0x0012, 4); //写到UI时钟寄存器
IEN3 |= 0x20; //设置外部中断IE
}
void RTC_ISR(void) interrupt 29 //秒29号中断函数
{
RTCSEL = RTCC;
RTCDAT &= RTCIF; //清RTC中断
RTCDAT |= RTCRE; //读RTC值到影子寄存器
RTCSEL = RTCS;
realTime.sec = RTCDAT;
RTCSEL = RTCM;
realTime.min = RTCDAT;
RTCSEL = RTCH;
realTime.hour = RTCDAT;
Write_Dgus((uint8_t*)&realTime, 0x0012, 4); //写到UI时钟寄存器
}
以上代码验证OK
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|