目前配置的只能是当天的闹钟,如何做到每天在设置的那个时间点进闹钟呢?哪位大佬帮忙解答下。GD32跟STM32不太一样,没法参照。以下是我做的闹钟代码,该如何修改成每天的闹钟。用的是库函数提供的寄存器操作方法。
void rtc_pre_config(void) { /* enable access to RTC registers in backup domain */ rcu_periph_clock_enable(RCU_PMU); pmu_backup_write_enable(); #if defined (RTC_CLOCK_SOURCE_IRC32K) rcu_osci_on(RCU_IRC32K); while(ERROR == rcu_osci_stab_wait(RCU_IRC32K)); rcu_rtc_clock_config(RCU_RTCSRC_IRC32K); prescaler_a = 0x63; //ck_apre频率 = RTC_CLOCK/(prescaler_a+1) = 32000/(99+1)=320HZ prescaler_s = 0x13F; //ck_spre频率 = ck_apre/(prescaler_s+1) = 320/(319+1)=1HZ #elif defined (RTC_CLOCK_SOURCE_LXTAL) rcu_osci_on(RCU_LXTAL); rcu_osci_stab_wait(RCU_LXTAL); rcu_rtc_clock_config(RCU_RTCSRC_LXTAL); prescaler_s = 0xFF; prescaler_a = 0x7F; #else #error RTC clock source should be defined #endif rcu_periph_clock_enable(RCU_RTC); rtc_register_sync_wait(); } void rtc_setup(uint8_t *rtc_buf) { /* setup RTC time value */ uint32_t tmp_hh = 0xFF; uint32_t tmp_mm = 0xFF; uint32_t tmp_ss = 0xFF; uint8_t year_data = 0; uint8_t date_data = 0; uint8_t alarm_date_data = 0; rtc_initpara.factor_asyn = prescaler_a; rtc_initpara.factor_syn = prescaler_s; year_data = HEXtoBCD(rtc_buf[6]); rtc_initpara.year = year_data; switch(rtc_buf[7]) { case 0x01: rtc_initpara.month = RTC_JAN; break; case 0x02: rtc_initpara.month = RTC_FEB; break; case 0x03: rtc_initpara.month = RTC_MAR; break; case 0x04: rtc_initpara.month = RTC_APR; break; case 0x05: rtc_initpara.month = RTC_MAY; break; case 0x06: rtc_initpara.month = RTC_JUN; break; case 0x07: rtc_initpara.month = RTC_JUL; break; case 0x08: rtc_initpara.month = RTC_AUG; break; case 0x09: rtc_initpara.month = RTC_SEP; break; case 0x0A: rtc_initpara.month = RTC_OCT; break; case 0x0B: rtc_initpara.month = RTC_NOV; break; case 0x0C: rtc_initpara.month = RTC_DEC; break; default: break; } date_data = HEXtoBCD(rtc_buf[8]); rtc_initpara.date = date_data; switch(rtc_buf[9]) { case 0x01: rtc_initpara.day_of_week = RTC_MONDAY; break; case 0x02: rtc_initpara.day_of_week = RTC_TUESDAY; break; case 0x03: rtc_initpara.day_of_week = RTC_WEDSDAY; break; case 0x04: rtc_initpara.day_of_week = RTC_THURSDAY; break; case 0x05: rtc_initpara.day_of_week = RTC_FRIDAY; break; case 0x06: rtc_initpara.day_of_week = RTC_SATURDAY; break; case 0x07: rtc_initpara.day_of_week = RTC_SUNDAY; break; default: break; } if(rtc_buf[10] == 0x00) { rtc_initpara.display_format = RTC_12HOUR; } else if(rtc_buf[10] == 0x01) { rtc_initpara.display_format = RTC_24HOUR; } if(rtc_buf[11] == 0x00) { rtc_initpara.am_pm = RTC_AM; } else if(rtc_buf[11] == 0x01) { rtc_initpara.am_pm = RTC_PM; } /* 输入当前时间 */ while(tmp_hh == 0xFF) { if(rtc_initpara.display_format == RTC_24HOUR) { tmp_hh = usart_input_threshold(rtc_buf[12], 23); } else { tmp_hh = usart_input_threshold(rtc_buf[12], 12); } rtc_initpara.hour = tmp_hh; } while(tmp_mm == 0xFF) { tmp_mm = usart_input_threshold(rtc_buf[13], 59); rtc_initpara.minute = tmp_mm; } while(tmp_ss == 0xFF) { tmp_ss = usart_input_threshold(rtc_buf[14], 59); rtc_initpara.second = tmp_ss; } /* RTC current time configuration */ if(ERROR == rtc_init(&rtc_initpara)) { printf("rn** RTC time configuration failed! **rn"); } else { printf("rn** RTC time configuration success! **rn"); } /* setup RTC alarm */ tmp_hh = 0xFF; tmp_mm = 0xFF; tmp_ss = 0xFF; rtc_alarm_disable(RTC_ALARM0); rtc_alarm.alarm_mask = RTC_ALARM_DATE_MASK|RTC_ALARM_HOUR_MASK|RTC_ALARM_MINUTE_MASK; rtc_alarm.weekday_or_date = RTC_ALARM_DATE_SELECTED; alarm_date_data = HEXtoBCD(rtc_buf[15]); rtc_alarm.alarm_day = alarm_date_data; if(rtc_buf[16] == 0x00) { rtc_alarm.am_pm = RTC_AM; } else if(rtc_buf[16] == 0x01) { rtc_alarm.am_pm = RTC_PM; } /* RTC alarm input */ while(tmp_hh == 0xFF) { if(rtc_initpara.display_format == RTC_24HOUR) { tmp_hh = usart_input_threshold(rtc_buf[17], 23); } else { tmp_hh = usart_input_threshold(rtc_buf[17], 12); } rtc_alarm.alarm_hour = tmp_hh; } while(tmp_mm == 0xFF) { tmp_mm = usart_input_threshold(rtc_buf[18], 59); rtc_alarm.alarm_minute = tmp_mm; } while(tmp_ss == 0xFF) { tmp_ss = usart_input_threshold(rtc_buf[19], 59); rtc_alarm.alarm_second = tmp_ss; } rtc_flag_clear(RTC_STAT_ALRM0F); exti_flag_clear(EXTI_17); /* RTC alarm configuration */ rtc_alarm_config(RTC_ALARM0, &rtc_alarm); nvic_irq_enable(RTC_Alarm_IRQn, 3, 0); rtc_alarm_enable(RTC_ALARM0); /* RTC alarm interrupt configuration */ exti_init(EXTI_17,EXTI_INTERRUPT, EXTI_TRIG_RISING); rtc_interrupt_enable(RTC_INT_ALARM0); } uint8_t usart_input_threshold(uint8_t buffer, uint32_t value) { uint32_t index = 0; uint32_t bcd_data = 0; bcd_data = HEXtoBCD(buffer); index = (bcd_data & 0x0F) + ((bcd_data >> 4) * 10); if (index > value) { printf("rn please input a valid number between 0 and %d rn", value); return 0xFF; } return bcd_data; } unsigned int HEXtoBCD(unsigned char hex_data) { unsigned int bcd_data = 0; unsigned char temp = 0; temp = hex_data % 100; bcd_data = ((unsigned int)hex_data) / 100 << 8; bcd_data = bcd_data | ((temp / 10) << 4); bcd_data = bcd_data | (temp % 10); return bcd_data; } void RTC_Alarm_IRQHandler(void) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; if(RESET != rtc_flag_get(RTC_STAT_ALRM0F)) { rtc_flag_clear(RTC_STAT_ALRM0F); exti_flag_clear(EXTI_17); rtc_alarm_disable(RTC_ALARM0); led_toggle(LED1); } }