嵌入式——RTC闹钟Alarm

开发流程

  1. 配置RTC时钟
  2. 设置RTC闹钟
  3. 配置RTC闹钟中断
  4. 实现中断函数
RTC闹钟初始化
// 闹钟外部中断
exti_flag_clear(EXTI_17);
exti_init(EXTI_17,EXTI_INTERRUPT,EXTI_TRIG_RISING);

// 重置闹钟
rtc_alarm_disable(RTC_ALARM0);

rtc_alarm_struct ras;
ras.alarm_mask = RTC_ALARM_HOUR_MASK | RTC_ALARM_MINUTE_MASK | RTC_ALARM_SECOND_MASK;
ras.weekday_or_date = RTC_ALARM_DATE_SELECTED;
ras.alarm_day = 0x21;
ras.alarm_hour = WRITE_BCD(23);
ras.alarm_minute = WRITE_BCD(59);
ras.alarm_second = WRITE_BCD(59);
ras.am_pm = RTC_AM;
rtc_alarm_config(RTC_ALARM0, &ras);

// 中断配置
nvic_irq_enable(RTC_Alarm_IRQn, 2, 2);
rtc_interrupt_enable(RTC_INT_ALARM0);
rtc_flag_clear(RTC_FLAG_ALRM0);

rtc_alarm_enable(RTC_ALARM0);
中断函数
void RTC_Alarm_IRQHandler() {
    if (SET == rtc_flag

你可能感兴趣的:(嵌入式开发,stm32,嵌入式硬件,物联网,单片机,arm开发)