你必须解锁时钟硬件。编写时间数据,并启动。我有一些代码在16位,你可以看到时钟硬件解锁。
以上来自于百度翻译
以下为原文
You have to unlock the clock hardware.
Write the time data and enable to start.
I have some code in 16bit where you can see the clock hardware unlocked.
.include "xc.inc"
.include "UtilityLib2.inc"
.global _setinternalclock
.section utilitycode,code
;----------------------------------------------------
.equ DT, w0 ;DateTime_t *
_setinternalclock: ;void setinternalclock(DateTime_t *DT); bcd
mov #0x55,w0
mov w0,NVMKEY
mov #0xAA,w0
mov w0,NVMKEY
bset RCFGCAL,#RTCWREN ;Set RTCWREN bit
bclr RCFGCAL,#RTCEN
mov RCFGCAL,w0
ior #0x300,w0 ;all
mov w0,RCFGCAL
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;set date
mov [DT+DT_Year],w0 ;get year
mov w0,RTCVAL ;set year
mov [DT+DT_DateMonth],w0 ;get date/month
mov w0,RTCVAL ;set month/date
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;set time
mov [DT+DT_HourDay],w0 ;get hour/day
mov w0,RTCVAL ;set hour/day
mov [DT+DT_SecondMinute],w0 ;get sec/min
mov w0,RTCVAL ;set min/sec
bset RCFGCAL,#RTCEN
bclr RCFGCAL,#RTCWREN ;Set RTCWREN bit
return
;----------------------------------------------------
.end
Using this structure
typedef struct{
union{
struct{
unsigned char Second;
unsigned char Minute;
};
unsigned int SecondMinute;
};
union{
struct{
unsigned char Hour;
unsigned char Day;
};
unsigned int HourDay;
};
union{
struct{
union{
struct{
unsigned char Date;
unsigned char Month;
};
unsigned int DateMonth;
};
unsigned int Year;
};
unsigned long TotalSeconds;
};
}DateTime_t;
你必须解锁时钟硬件。编写时间数据,并启动。我有一些代码在16位,你可以看到时钟硬件解锁。
以上来自于百度翻译
以下为原文
You have to unlock the clock hardware.
Write the time data and enable to start.
I have some code in 16bit where you can see the clock hardware unlocked.
.include "xc.inc"
.include "UtilityLib2.inc"
.global _setinternalclock
.section utilitycode,code
;----------------------------------------------------
.equ DT, w0 ;DateTime_t *
_setinternalclock: ;void setinternalclock(DateTime_t *DT); bcd
mov #0x55,w0
mov w0,NVMKEY
mov #0xAA,w0
mov w0,NVMKEY
bset RCFGCAL,#RTCWREN ;Set RTCWREN bit
bclr RCFGCAL,#RTCEN
mov RCFGCAL,w0
ior #0x300,w0 ;all
mov w0,RCFGCAL
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;set date
mov [DT+DT_Year],w0 ;get year
mov w0,RTCVAL ;set year
mov [DT+DT_DateMonth],w0 ;get date/month
mov w0,RTCVAL ;set month/date
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;set time
mov [DT+DT_HourDay],w0 ;get hour/day
mov w0,RTCVAL ;set hour/day
mov [DT+DT_SecondMinute],w0 ;get sec/min
mov w0,RTCVAL ;set min/sec
bset RCFGCAL,#RTCEN
bclr RCFGCAL,#RTCWREN ;Set RTCWREN bit
return
;----------------------------------------------------
.end
Using this structure
typedef struct{
union{
struct{
unsigned char Second;
unsigned char Minute;
};
unsigned int SecondMinute;
};
union{
struct{
unsigned char Hour;
unsigned char Day;
};
unsigned int HourDay;
};
union{
struct{
union{
struct{
unsigned char Date;
unsigned char Month;
};
unsigned int DateMonth;
};
unsigned int Year;
};
unsigned long TotalSeconds;
};
}DateTime_t;
举报