本帖最后由 mzxh 于 2021-6-10 10:58 编辑
扫描可以正常获得时间,下面是中端设置和中断函数,看看有没有问题
void rtc_second_int_setup(void)//秒中断还没实现
{
rtc_alarm_subsecond_config(0x00,0x7fff);//亚秒闹钟
//rtc_interrupt_enable(RTC_INT_ALARM);
RTC_WPK = RTC_UNLOCK_KEY1;//解锁
RTC_WPK = RTC_UNLOCK_KEY2;
RTC_ALRM0TD = RTC_ALRM0TD_MSKD | RTC_ALRM0TD_MSKH |RTC_ALRM0TD_MSKM ;//| RTC_ALRM0TD_MSKS;
RTC_CTL |= RTC_CTL_ALRM0EN;//使能闹钟功能
RTC_CTL |= RTC_CTL_ALRM0IE;//使能闹钟中断
/* enable the write protection */
RTC_WPK = RTC_LOCK_KEY;//锁定
exti_init(EXTI_17,EXTI_INTERRUPT,EXTI_TRIG_RISING);
exti_interrupt_enable(EXTI_17);
nvic_irq_enable(RTC_IRQn,2U,0U);
}
void RTC_IRQHandler(void)
{
// if(RTC_STAT & RTC_STAT_ALRM0F)
// {
rtc_current_time_get(& rtc_initpara);
// lcd_show_str(35,30,Num2Str(rtc_initpara.rtc_second ,2,0,0),RED,BLUE);
// lcd_show_str(55,30,Num2Str(rtc_initpara.rtc_minute ,2,0,0),RED,BLUE);
RTC_STAT &=(~RTC_STAT_ALRM0F);
rtc_flag_clear(RTC_FLAG_ALARM0);
exti_flag_clear(EXTI_17);
// }
}
下面是扫描获得时间,和中断函数不同时使用
if(RTC_STAT & RTC_STAT_ALRM0F)
{
// rtc_current_time_get(& rtc_initpara);
rtc_initpara.rtc_second=(uint8_t)GET_TIME_SC(RTC_TIME);
rtc_initpara.rtc_minute=(uint8_t)GET_TIME_MN(RTC_TIME);
rtc_initpara.rtc_hour=(uint8_t)GET_TIME_HR(RTC_TIME);
lcd_show_str(35,30,Num2Str(rtc_initpara.rtc_second ,2,0,0),RED,BLUE);
lcd_show_str(95,30,Num2Str(rtc_initpara.rtc_minute ,2,0,0),RED,BLUE);
RTC_STAT &=(~RTC_STAT_ALRM0F);
}
|