谢谢你们的建议,我能够根据你们对RTCC被重置的洞察来解决这个问题。我找到了解决方案,MCC代码总是初始化RTCC,并且不查看RTCC是否已经被初始化。在我看来,提供一个选项“保留时间”是个不错的主意,如果时间已经设置了,则不重置时间。如果在初始化之前粘贴这段代码,则只有当设备首次运行(然后设置VBPOR)或发生VBPOR事件(由于电池耗尽,RTCC值可能不正确)时,时间才会初始化。如果程序时间被定义,时间将由程序员重新编程并保留在复位上。这个函数应该在RTCC初始化之前被调用。或者,如果不想使用MCC代码,则可以通过布尔指示天气来替换RTCC_TimeReset函数,或者不需要初始化RTCC。
以上来自于百度翻译
以下为原文
Thank you rodims for your suggestion, i was able to fix the problem based on you insight that the RTCC is reset.
I found the solution, the MCC code always initializes the RTCC and doesn't look if the RTCC is already initialized. It seems to me it would be a very good idea to provide an option "retain time" that does not reset the time if the time is already set. If you paste this snipped of code before the initialization the time will only initialize if the device runs for the first time (then VBPOR is set) or a VBPOR event occurs (RTCC values can be incorrect due to a drained battery). If PROGRAM_TIME is defined the time will be reprogrammed by the programmer and retained on reset. This function should be called
Before the RTCC initialization. Alternatively, if you don't want to use MCC code, you can replace the RTCC_TimeReset function by a boolean indication weather or not the RTCC needs to be initialized.
void check_rtcc_initialization( void )
{
RTCC_TimeReset(true); //By default retain value
if(RCON2bits.VBPOR) //RTCC value are not reliable
{
RCON2bits.VBPOR = 0; //Unset the flag
RTCC_TimeReset(false); //Initialize RTCC with new value
} else
{
#ifdef PROGRAM_TIME
if(RCON2bits.VBAT) //VBAT was not connected, RTCC is wrong. VBAT = 0 after programming
{
RCON2bits.VBAT = 0; //Unset the flag
RTCC_TimeReset(true); //No initialization needed
} else
{
RTCC_TimeReset(false); //Initialize RTCC with new value
}
#endif
}
}
谢谢你们的建议,我能够根据你们对RTCC被重置的洞察来解决这个问题。我找到了解决方案,MCC代码总是初始化RTCC,并且不查看RTCC是否已经被初始化。在我看来,提供一个选项“保留时间”是个不错的主意,如果时间已经设置了,则不重置时间。如果在初始化之前粘贴这段代码,则只有当设备首次运行(然后设置VBPOR)或发生VBPOR事件(由于电池耗尽,RTCC值可能不正确)时,时间才会初始化。如果程序时间被定义,时间将由程序员重新编程并保留在复位上。这个函数应该在RTCC初始化之前被调用。或者,如果不想使用MCC代码,则可以通过布尔指示天气来替换RTCC_TimeReset函数,或者不需要初始化RTCC。
以上来自于百度翻译
以下为原文
Thank you rodims for your suggestion, i was able to fix the problem based on you insight that the RTCC is reset.
I found the solution, the MCC code always initializes the RTCC and doesn't look if the RTCC is already initialized. It seems to me it would be a very good idea to provide an option "retain time" that does not reset the time if the time is already set. If you paste this snipped of code before the initialization the time will only initialize if the device runs for the first time (then VBPOR is set) or a VBPOR event occurs (RTCC values can be incorrect due to a drained battery). If PROGRAM_TIME is defined the time will be reprogrammed by the programmer and retained on reset. This function should be called
Before the RTCC initialization. Alternatively, if you don't want to use MCC code, you can replace the RTCC_TimeReset function by a boolean indication weather or not the RTCC needs to be initialized.
void check_rtcc_initialization( void )
{
RTCC_TimeReset(true); //By default retain value
if(RCON2bits.VBPOR) //RTCC value are not reliable
{
RCON2bits.VBPOR = 0; //Unset the flag
RTCC_TimeReset(false); //Initialize RTCC with new value
} else
{
#ifdef PROGRAM_TIME
if(RCON2bits.VBAT) //VBAT was not connected, RTCC is wrong. VBAT = 0 after programming
{
RCON2bits.VBAT = 0; //Unset the flag
RTCC_TimeReset(true); //No initialization needed
} else
{
RTCC_TimeReset(false); //Initialize RTCC with new value
}
#endif
}
}
举报