int main(void) { uint8_t i; SystemClock_UART1_init(); sys_rtc_init(2023,6,2,12,0,0); /// 调用这一句后 下面的不执行 printf("begin run version 20230510\n");
void sys_rtc_init(UINT16 y, UINT16 mon, UINT16 d, UINT16 h, UINT16 m, UINT16 s) { /// //使用内部的32K RC作为RTC的时钟,由于rc振荡器是误差比较大,所以wch提供了校准函数,并且根据需求是校准到32Khz 还是32.768khz #if( CLK_OSC32K ) R8_SAFE_ACCESS_SIG = 0x57; R8_SAFE_ACCESS_SIG = 0xa8; R8_CK32K_CONFIG &= ~(RB_CLK_OSC32K_XT|RB_CLK_XT32K_PON); R8_CK32K_CONFIG |= RB_CLK_INT32K_PON; R8_SAFE_ACCESS_SIG = 0; Calibration_LSI(); #else R8_SAFE_ACCESS_SIG = 0x57; R8_SAFE_ACCESS_SIG = 0xa8; R8_CK32K_CONFIG |= RB_CLK_OSC32K_XT | RB_CLK_INT32K_PON | RB_CLK_XT32K_PON; R8_SAFE_ACCESS_SIG = 0; #endif RTC_InitTime( y, mon, d, h, m, s ); //RTC时钟初始化当前时间 RTC_TMRFunCfg(Period_1_S); NVIC_EnableIRQ(RTC_IRQn); } __attribute__((interrupt("WCH-Interrupt-fast"))) // wch的硬件压栈 __attribute__((section(".highcode"))) // 需要放到RAM里面 void RTC_IRQHandler( void ) { UINT16 py; UINT16 pmon;UINT16 pd;UINT16 ph;UINT16 pm;UINT16 ps; if(RTC_GetITFlag(RTC_TMR_EVENT)){ RTC_GetTime(&py,&pmon,&pd,&ph,&pm,&ps); printf("%04d-%02d-%02d %02d:%02d:%02d\r\n",py,pmon,pd,ph,pm,ps); //这里每秒正常打印 RTC_ClearITFlag(RTC_TMR_EVENT); } }
main 函数里调用 sys_rtc_init 后就不往下执行了
热门产品 :
CH634: 4端口USB3.0 HUB控制器芯片