完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
目前配置的只能是当天的闹钟,如何做到每天在设置的那个时间点进闹钟呢?哪位大佬帮忙解答下。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); } } |
|
相关推荐
3个回答
|
|
rtc_flag_clear(RTC_STAT_ALRM0F);
这句,要调整一下位置或算法; 保证 1. 本次叫醒后,虽然被清除了本标志, 2. 新一天要重新置位本标志; |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
464 浏览 0 评论
478 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
439 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
994 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1056 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11788 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 16:40 , Processed in 0.906120 second(s), Total 97, Slave 75 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号