📄 rtc.c
字号:
//****************************************************************************
// @Module Real Timer Clock (RTC)
// @Filename RTC.C
// @Project rtc.dav
//----------------------------------------------------------------------------
//****************************************************************************
// @Project Includes
//****************************************************************************
#include "MAIN.H"
extern int n;
/****************************************************************************************************************
@Function void RTC_vInit(void)
*****************************************************************************************************************/
void RTC_vInit(void)
{
MAIN_vUnlockProtecReg(); //unlock SYSCON0
SYSCON0_RTCCM = 0; // enable access to control bits
/// -----------------------------------------------------------------------
/// Configuration of the RTC Counter:
/// -----------------------------------------------------------------------
/// - RTC input frequency is 375.000 kHz
/// - the input clock is divided by factor 8
/// - counter is started after initialization
while((RTC_CON & 0x8000) == 0x0000); // wait until access is possible
RTC_CON = 0x0002; // load RTC control register
/// - overflow period on T14: 10.0053 [ms]
/// - overflow period on CNT0: 40.0213 [ms]
/// - overflow period on CNT1: 2.5614 [s]
/// - overflow period on CNT2: 2.7321 [min]
/// - overflow period on CNT3: 1.9428 [days]
RTC_T14REL = 0xFE2B; // load T14 count/reload register
RTC_RTCL = 0x03FC; // load RTC low register
RTC_RELL = 0x03FC; // load RTC reload low register
RTC_RTCH = 0x0000; // load RTC high register
RTC_RELH = 0x0000; // load RTC reload high register
/// -----------------------------------------------------------------------
/// Configuration of the used RTC Interrupts:
/// -----------------------------------------------------------------------
/// RTC service request node configuration:
/// - RTC interrupt priority level (ILVL) = 13
/// - RTC interrupt group level (GLVL) = 1
/// - RTC group priority extension (GPX) = 0
RTC_IC = 0x0075;
RTC_ISNC = 0x0004; // load RTC interrupt sub node register
RTC_CON_RUN = 1; // starts the counter
// USER CODE BEGIN (Init,3)
// USER CODE END
} // End of function RTC_vInit
//****************************************************************************
// @Function void RTC_viRTC(void)
//
//----------------------------------------------------------------------------
// @Description This is the RTC interrupt service routine. It is called up
// when:
// - counter T14 overflows and is reloaded
// - counter CNT0 overflows and is reloaded
// - counter CNT1 overflows and is reloaded
// - counter CNT2 overflows and is reloaded
// - counter CNT3 overflows and is reloaded
// This interrupt request may eg. be used to provide a system
// time tick independent of the CPU frequency, or to wake up
// regularly from idle mode.
//
// Please note that you have to add application specific code
// to this function.
//****************************************************************************
void RTC_viRTC(void) interrupt RTCINT
{
if(RTC_ISNC_0IR) // if counter CNT0 overflow
{
// USER CODE BEGIN (RTC,4)
// USER CODE END
RTC_ISNC_0IR = 0;
}
if(n%2)
{
P1H = 0x00FF;
P1L = 0x0000;
}
else
{
P1H = 0x0000;
P1L = 0x00FF;
}
n++;
}
// End of function RTC_viRTC
// USER CODE BEGIN (RTC_General,10)
// USER CODE END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -