当前位置: 首页 > news >正文

视频网站不赚钱为什么还做镇江百度seo

视频网站不赚钱为什么还做,镇江百度seo,网站页面一般做多大,商务网站建设策划书2000字实时时钟(Real Time Clock,RTC),本质是一个计数器,计数频率常为秒,专门用来记录时间。 普通定时器无法掉电运行!但RTC可由VBAT备用电源供电,断电不断时 这里讲F1系列的RTC 可以产生三个中断信号&#xff…

实时时钟(Real Time Clock,RTC),本质是一个计数器,计数频率常为秒,专门用来记录时间。

普通定时器无法掉电运行!但RTC可由VBAT备用电源供电,断电不断时

这里讲F1系列的RTC

可以产生三个中断信号,秒  闹钟  溢出信号

其中闹钟可以唤醒wwdg和iwdg

后备寄存器:

后备寄存器不仅有存数据的地方还有存状态,存配置rtc等后备外设的配置寄存器的存在,这些寄存器全部都复位不重置,所以可以在有备用电池的状态下做点文章

因为rcc内有状态位在不断电情况下可以知道上次复位是因为什么造成的

标准库还有用后备寄存器存数据的  temper引脚防破解  校准时钟输出等实验,正点原子hal教学没有,得自己探索

你选时钟源的时候如果32.768khz坏了,也可以选择rc振荡器40khz和高速内部rc振荡器但不推荐,因为他俩很容易受外部影响

你可以获取分频器的分频计数值来更加精确的处理得出时间 

函数解析:

下面的函数是正点原子自己写的,专门用于处理时间戳的函数,你也可以自己用time.h跟标准库那时候一样

rtc.c

#include "./BSP/RTC/rtc.h"
#include "./BSP/LED/led.h"
#include "./SYSTEM/usart/usart.h"
#include "./SYSTEM/delay/delay.h"RTC_HandleTypeDef g_rtc_handle; /* RTC控制句柄 */
_calendar_obj calendar;         /* 时间结构体 *//*** @brief       RTC写入后备区域SRAM* @param       bkrx : 后备区寄存器编号,范围:0~41对应 RTC_BKP_DR1~RTC_BKP_DR42* @param       data : 要写入的数据,16位长度* @retval      无*/
void rtc_write_bkr(uint32_t bkrx, uint16_t data)
{HAL_PWR_EnableBkUpAccess(); /* 取消备份区写保护 */HAL_RTCEx_BKUPWrite(&g_rtc_handle, bkrx + 1, data);
}/*** @brief       RTC读取后备区域SRAM* @param       bkrx : 后备区寄存器编号,范围:0~41对应 RTC_BKP_DR1~RTC_BKP_DR42* @retval      读取到的值*/
uint16_t rtc_read_bkr(uint32_t bkrx)
{uint32_t temp = 0;temp = HAL_RTCEx_BKUPRead(&g_rtc_handle, bkrx + 1);return (uint16_t)temp; /* 返回读取到的值 */
}/*** @brief       RTC初始化*   @note*              默认尝试使用LSE,当LSE启动失败后,切换为LSI.*              通过BKP寄存器0的值,可以判断RTC使用的是LSE/LSI:*              当BKP0==0X5050时,使用的是LSE*              当BKP0==0X5051时,使用的是LSI*              注意:切换LSI/LSE将导致时间/日期丢失,切换后需重新设置.** @param       无* @retval      0,成功*              1,进入初始化模式失败*/
uint8_t rtc_init(void)
{/* 检查是不是第一次配置时钟 */uint16_t bkpflag = 0;__HAL_RCC_PWR_CLK_ENABLE(); /* 使能PWR电源时钟 */__HAL_RCC_BKP_CLK_ENABLE(); /* 使能BKP备份时钟 */HAL_PWR_EnableBkUpAccess(); /* 取消备份区写保护 */g_rtc_handle.Instance = RTC;g_rtc_handle.Init.AsynchPrediv = 32767;     /* 时钟周期设置,理论值:32767, 这里也可以用 RTC_AUTO_1_SECOND */g_rtc_handle.Init.OutPut = RTC_OUTPUTSOURCE_NONE;if (HAL_RTC_Init(&g_rtc_handle) != HAL_OK)  /* 初始化RTC */{return 1;}bkpflag = rtc_read_bkr(0);  /* 读取BKP0的值 */if ((bkpflag != 0X5050) && (bkpflag != 0x5051))         /* 之前未初始化过,重新配置 */{rtc_set_time(2020, 4, 25, 20, 25, 35);              /* 设置时间 */}__HAL_RTC_ALARM_ENABLE_IT(&g_rtc_handle, RTC_IT_SEC);   /* 允许秒中断 */__HAL_RTC_ALARM_ENABLE_IT(&g_rtc_handle, RTC_IT_ALRA);  /* 允许闹钟中断 */HAL_NVIC_SetPriority(RTC_IRQn, 0x2, 0);                 /* 设置RTC中断 */HAL_NVIC_EnableIRQ(RTC_IRQn);                           /* 使能中断 */rtc_get_time(); /* 更新时间 */return 0;
}/*** @brief       RTC初始化*   @note*              RTC底层驱动,时钟配置,此函数会被HAL_RTC_Init()调用* @param       hrtc:RTC句柄* @retval      无*/
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{uint16_t retry = 200;__HAL_RCC_RTC_ENABLE();     /* RTC时钟使能 */RCC_OscInitTypeDef rcc_oscinitstruct;RCC_PeriphCLKInitTypeDef rcc_periphclkinitstruct;/* 使用寄存器的方式去检测LSE是否可以正常工作 */RCC->BDCR |= 1 << 0;    /* 开启外部低速振荡器LSE */while (retry && ((RCC->BDCR & 0X02) == 0))  /* 等待LSE准备好 */{retry--;delay_ms(5);}if (retry == 0)     /* LSE起振失败 使用LSI */{rcc_oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;  /* 选择要配置的振荡器 */rcc_oscinitstruct.LSIState = RCC_LSI_ON;                    /* LSI状态:开启 */rcc_oscinitstruct.PLL.PLLState = RCC_PLL_NONE;              /* PLL无配置 */HAL_RCC_OscConfig(&rcc_oscinitstruct);                      /* 配置设置的rcc_oscinitstruct */rcc_periphclkinitstruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;   /* 选择要配置的外设 RTC */rcc_periphclkinitstruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;   /* RTC时钟源选择 LSI */HAL_RCCEx_PeriphCLKConfig(&rcc_periphclkinitstruct);                /* 配置设置的rcc_periphClkInitStruct */rtc_write_bkr(0, 0X5051);}else{rcc_oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_LSE ; /* 选择要配置的振荡器 */rcc_oscinitstruct.LSEState = RCC_LSE_ON;                    /* LSE状态:开启 */rcc_oscinitstruct.PLL.PLLState = RCC_PLL_NONE;              /* PLL不配置 */HAL_RCC_OscConfig(&rcc_oscinitstruct);                      /* 配置设置的rcc_oscinitstruct */rcc_periphclkinitstruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;   /* 选择要配置外设 RTC */rcc_periphclkinitstruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;   /* RTC时钟源选择LSE */HAL_RCCEx_PeriphCLKConfig(&rcc_periphclkinitstruct);                /* 配置设置的rcc_periphclkinitstruct */rtc_write_bkr(0, 0X5055);}
}/*** @brief       RTC时钟中断*   @note      秒钟中断 / 闹钟中断 共用同一个中断服务函数*              根据RTC_CRL寄存器的 SECF 和 ALRF 位区分是哪个中断* @param       无* @retval      无*/
void RTC_IRQHandler(void)
{if (__HAL_RTC_ALARM_GET_FLAG(&g_rtc_handle, RTC_FLAG_SEC) != RESET)     /* 秒中断 */{rtc_get_time();     /* 更新时间 */__HAL_RTC_ALARM_CLEAR_FLAG(&g_rtc_handle, RTC_FLAG_SEC);            /* 清除秒中断 *///printf("sec:%d\r\n", calendar.sec);   /* 打印秒钟 */}if (__HAL_RTC_ALARM_GET_FLAG(&g_rtc_handle, RTC_FLAG_ALRAF) != RESET)   /* 闹钟中断 */{__HAL_RTC_ALARM_CLEAR_FLAG(&g_rtc_handle, RTC_FLAG_ALRAF);          /* 清除闹钟中断 */printf("Alarm Time:%d-%d-%d %d:%d:%d\n", calendar.year, calendar.month, calendar.date, calendar.hour, calendar.min, calendar.sec);}__HAL_RTC_ALARM_CLEAR_FLAG(&g_rtc_handle, RTC_FLAG_OW);                 /* 清除溢出中断标志 */while (!__HAL_RTC_ALARM_GET_FLAG(&g_rtc_handle, RTC_FLAG_RTOFF));       /* 等待RTC寄存器操作完成, 即等待RTOFF == 1 */
}/*** @brief       判断年份是否是闰年*   @note      月份天数表:*              月份   1  2  3  4  5  6  7  8  9  10 11 12*              闰年   31 29 31 30 31 30 31 31 30 31 30 31*              非闰年 31 28 31 30 31 30 31 31 30 31 30 31* @param       year : 年份* @retval      0, 非闰年; 1, 是闰年;*/
static uint8_t rtc_is_leap_year(uint16_t year)
{/* 闰年规则: 四年闰百年不闰,四百年又闰 */if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){return 1;}else{return 0;}
}/*** @brief       设置时间, 包括年月日时分秒*   @note      以1970年1月1日为基准, 往后累加时间*              合法年份范围为: 1970 ~ 2105年HAL默认为年份起点为2000年* @param       syear : 年份* @param       smon  : 月份* @param       sday  : 日期* @param       hour  : 小时* @param       min   : 分钟* @param       sec   : 秒钟* @retval      0, 成功; 1, 失败;*/
uint8_t rtc_set_time(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec)
{uint32_t seccount = 0;seccount = rtc_date2sec(syear, smon, sday, hour, min, sec); /* 将年月日时分秒转换成总秒钟数 */__HAL_RCC_PWR_CLK_ENABLE(); /* 使能电源时钟 */__HAL_RCC_BKP_CLK_ENABLE(); /* 使能备份域时钟 */HAL_PWR_EnableBkUpAccess(); /* 取消备份域写保护 *//* 上面三步是必须的! */RTC->CRL |= 1 << 4;         /* 进入配置模式 */RTC->CNTL = seccount & 0xffff;RTC->CNTH = seccount >> 16;RTC->CRL &= ~(1 << 4);      /* 退出配置模式 */while (!__HAL_RTC_ALARM_GET_FLAG(&g_rtc_handle, RTC_FLAG_RTOFF));       /* 等待RTC寄存器操作完成, 即等待RTOFF == 1 */return 0;
}/*** @brief       设置闹钟, 具体到年月日时分秒*   @note      以1970年1月1日为基准, 往后累加时间*              合法年份范围为: 1970 ~ 2105年* @param       syear : 年份* @param       smon  : 月份* @param       sday  : 日期* @param       hour  : 小时* @param       min   : 分钟* @param       sec   : 秒钟* @retval      0, 成功; 1, 失败;*/
uint8_t rtc_set_alarm(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec)
{uint32_t seccount = 0;seccount = rtc_date2sec(syear, smon, sday, hour, min, sec); /* 将年月日时分秒转换成总秒钟数 */__HAL_RCC_PWR_CLK_ENABLE(); /* 使能电源时钟 */__HAL_RCC_BKP_CLK_ENABLE(); /* 使能备份域时钟 */HAL_PWR_EnableBkUpAccess(); /* 取消备份域写保护 *//* 上面三步是必须的! */RTC->CRL |= 1 << 4;         /* 进入配置模式 */RTC->ALRL = seccount & 0xffff;RTC->ALRH = seccount >> 16;RTC->CRL &= ~(1 << 4);      /* 退出配置模式 */while (!__HAL_RTC_ALARM_GET_FLAG(&g_rtc_handle, RTC_FLAG_RTOFF));       /* 等待RTC寄存器操作完成, 即等待RTOFF == 1 */return 0;
}/*** @brief       得到当前的时间*   @note      该函数不直接返回时间, 时间数据保存在calendar结构体里面* @param       无* @retval      无*/
void rtc_get_time(void)
{static uint16_t daycnt = 0;uint32_t seccount = 0;uint32_t temp = 0;uint16_t temp1 = 0;const uint8_t month_table[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* 平年的月份日期表 */seccount = RTC->CNTH; /* 得到计数器中的值(秒钟数) */seccount <<= 16;seccount += RTC->CNTL;temp = seccount / 86400; /* 得到天数(秒钟数对应的) */if (daycnt != temp) /* 超过一天了 */{daycnt = temp;temp1 = 1970;   /* 从1970年开始 */while (temp >= 365){if (rtc_is_leap_year(temp1)) /* 是闰年 */{if (temp >= 366){temp -= 366;    /* 闰年的秒钟数 */}else{break;}}else{temp -= 365;        /* 平年 */}temp1++;}calendar.year = temp1;      /* 得到年份 */temp1 = 0;while (temp >= 28)      /* 超过了一个月 */{if (rtc_is_leap_year(calendar.year) && temp1 == 1) /* 当年是不是闰年/2月份 */{if (temp >= 29){temp -= 29; /* 闰年的秒钟数 */}else{break;}}else{if (temp >= month_table[temp1]){temp -= month_table[temp1]; /* 平年 */}else{break;}}temp1++;}calendar.month = temp1 + 1; /* 得到月份 */calendar.date = temp + 1;   /* 得到日期 */}temp = seccount % 86400;                                                    /* 得到秒钟数 */calendar.hour = temp / 3600;                                                /* 小时 */calendar.min = (temp % 3600) / 60;                                          /* 分钟 */calendar.sec = (temp % 3600) % 60;                                          /* 秒钟 */calendar.week = rtc_get_week(calendar.year, calendar.month, calendar.date); /* 获取星期 */
}/*** @brief       将年月日时分秒转换成秒钟数*   @note      输入公历日期得到星期(起始时间为: 公元0年3月1日开始, 输入往后的任何日期, 都可以获取正确的星期)*              使用 基姆拉尔森计算公式 计算, 原理说明见此贴:*              https://www.cnblogs.com/fengbohello/p/3264300.html* @param       syear : 年份* @param       smon  : 月份* @param       sday  : 日期* @retval      0, 星期天; 1 ~ 6: 星期一 ~ 星期六*/
uint8_t rtc_get_week(uint16_t year, uint8_t month, uint8_t day)
{uint8_t week = 0;if (month < 3){month += 12;--year;}week = (day + 1 + 2 * month + 3 * (month + 1) / 5 + year + (year >> 2) - year / 100 + year / 400) % 7;return week;
}/*** @brief       将年月日时分秒转换成秒钟数*   @note      以1970年1月1日为基准, 1970年1月1日, 0时0分0秒, 表示第0秒钟*              最大表示到2105年, 因为uint32_t最大表示136年的秒钟数(不包括闰年)!*              本代码参考只linux mktime函数, 原理说明见此贴:*              http://www.openedv.com/thread-63389-1-1.html* @param       syear : 年份* @param       smon  : 月份* @param       sday  : 日期* @param       hour  : 小时* @param       min   : 分钟* @param       sec   : 秒钟* @retval      转换后的秒钟数*/
static long rtc_date2sec(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec)
{uint32_t Y, M, D, X, T;signed char monx = smon;    /* 将月份转换成带符号的值, 方便后面运算 */if (0 >= (monx -= 2))       /* 1..12 -> 11,12,1..10 */{monx += 12; /* Puts Feb last since it has leap day */syear -= 1;}Y = (syear - 1) * 365 + syear / 4 - syear / 100 + syear / 400; /* 公元元年1到现在的闰年数 */M = 367 * monx / 12 - 30 + 59;D = sday - 1;X = Y + M + D - 719162;                      /* 减去公元元年到1970年的天数 */T = ((X * 24 + hour) * 60 + min) * 60 + sec; /* 总秒钟数 */return T;
}

rtc.h

#ifndef __RTC_H
#define __RTC_H#include "./SYSTEM/sys/sys.h"/* 时间结构体, 包括年月日周时分秒等信息 */
typedef struct
{uint8_t hour;       /* 时 */uint8_t min;        /* 分 */uint8_t sec;        /* 秒 *//* 公历年月日周 */uint16_t year;      /* 年 */uint8_t  month;     /* 月 */uint8_t  date;      /* 日 */uint8_t  week;      /* 周 */
} _calendar_obj;extern _calendar_obj calendar;                      /* 时间结构体 *//* 静态函数 */
static uint8_t rtc_is_leap_year(uint16_t year);     /* 判断当前年份是不是闰年 */
static long rtc_date2sec(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec);   /* 将年月日时分秒转换成秒钟数 *//* 接口函数 */
uint8_t rtc_init(void);                             /* 初始化RTC */
void rtc_get_time(void);                            /* 获取RTC时间信息 */
uint16_t rtc_read_bkr(uint32_t bkrx);               /* 读取后备寄存器 */
void rtc_write_bkr(uint32_t bkrx, uint16_t data);   /* 写后备寄存器 */ 
uint8_t rtc_get_week(uint16_t year, uint8_t month, uint8_t day);    /* 根据年月日获取星期几 */
uint8_t rtc_set_time(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec);   /* 设置时间 */
uint8_t rtc_set_alarm(uint16_t syear, uint8_t smon, uint8_t sday, uint8_t hour, uint8_t min, uint8_t sec);  /* 设置闹钟时间 */#endif


文章转载自:
http://dinncoflashhouse.wbqt.cn
http://dinncounsympathizing.wbqt.cn
http://dinncomicroinjection.wbqt.cn
http://dinncoshipentine.wbqt.cn
http://dinncomonandry.wbqt.cn
http://dinncohepatin.wbqt.cn
http://dinncoasexual.wbqt.cn
http://dinnconegation.wbqt.cn
http://dinncodiffluent.wbqt.cn
http://dinncokinda.wbqt.cn
http://dinncoforme.wbqt.cn
http://dinncorichina.wbqt.cn
http://dinncosubhedral.wbqt.cn
http://dinncotransductant.wbqt.cn
http://dinncooverrate.wbqt.cn
http://dinncobiocenose.wbqt.cn
http://dinncoredd.wbqt.cn
http://dinncozymogenesis.wbqt.cn
http://dinncoaccommodative.wbqt.cn
http://dinncoarchon.wbqt.cn
http://dinncopack.wbqt.cn
http://dinncomacassar.wbqt.cn
http://dinncocaroche.wbqt.cn
http://dinncoconvulsionary.wbqt.cn
http://dinncothereanent.wbqt.cn
http://dinncocymling.wbqt.cn
http://dinncoimmoralism.wbqt.cn
http://dinncohemline.wbqt.cn
http://dinncoword.wbqt.cn
http://dinncoscrambler.wbqt.cn
http://dinncosuborbicular.wbqt.cn
http://dinncocomandante.wbqt.cn
http://dinncofallfish.wbqt.cn
http://dinncoatherogenic.wbqt.cn
http://dinncomasturbation.wbqt.cn
http://dinncocondiments.wbqt.cn
http://dinncotayside.wbqt.cn
http://dinncomicrometry.wbqt.cn
http://dinncofondu.wbqt.cn
http://dinncofirer.wbqt.cn
http://dinncopress.wbqt.cn
http://dinncogrammalogue.wbqt.cn
http://dinncoexceed.wbqt.cn
http://dinncohexastich.wbqt.cn
http://dinncospinulate.wbqt.cn
http://dinncoincabloc.wbqt.cn
http://dinncocoreless.wbqt.cn
http://dinncojoint.wbqt.cn
http://dinncoknickerbocker.wbqt.cn
http://dinncolanceolar.wbqt.cn
http://dinncopalpebral.wbqt.cn
http://dinncomicroreproduction.wbqt.cn
http://dinncolinkswoman.wbqt.cn
http://dinncocompression.wbqt.cn
http://dinncolumpenprole.wbqt.cn
http://dinncocamboose.wbqt.cn
http://dinncochief.wbqt.cn
http://dinncowdp.wbqt.cn
http://dinncocirrose.wbqt.cn
http://dinncorenovate.wbqt.cn
http://dinncochlorphenol.wbqt.cn
http://dinncoxenon.wbqt.cn
http://dinncopulpit.wbqt.cn
http://dinncobackscattering.wbqt.cn
http://dinncopolyvinyl.wbqt.cn
http://dinncocontraposition.wbqt.cn
http://dinncoindefeasible.wbqt.cn
http://dinncolinkboy.wbqt.cn
http://dinncodispauperization.wbqt.cn
http://dinncohumiliating.wbqt.cn
http://dinncosupe.wbqt.cn
http://dinncocamise.wbqt.cn
http://dinncohighjacker.wbqt.cn
http://dinncoglycoprotein.wbqt.cn
http://dinncohimavat.wbqt.cn
http://dinncounemancipated.wbqt.cn
http://dinncoreification.wbqt.cn
http://dinncohulahula.wbqt.cn
http://dinncographical.wbqt.cn
http://dinncoambisyllabic.wbqt.cn
http://dinncotapette.wbqt.cn
http://dinnconetfs.wbqt.cn
http://dinncomanaging.wbqt.cn
http://dinncooily.wbqt.cn
http://dinncobulla.wbqt.cn
http://dinncoseminivorous.wbqt.cn
http://dinncosociology.wbqt.cn
http://dinncohuly.wbqt.cn
http://dinncoemit.wbqt.cn
http://dinnconoil.wbqt.cn
http://dinncoenfranchisement.wbqt.cn
http://dinncobelated.wbqt.cn
http://dinncoluncheteria.wbqt.cn
http://dinncobusinessman.wbqt.cn
http://dinncofluorocarbon.wbqt.cn
http://dinncouserkit.wbqt.cn
http://dinnconubia.wbqt.cn
http://dinncokemp.wbqt.cn
http://dinncomarantic.wbqt.cn
http://dinncomsr.wbqt.cn
http://www.dinnco.com/news/120449.html

相关文章:

  • 毕设做网站需要买域名么去了外包简历就毁了吗
  • 一个人做网站难吗南通百度网站快速优化
  • 临海商用高端网站设计新感觉建站网店买卖有哪些平台
  • 网站开发人员需求抖音seo是什么
  • 有什么网站可以在线做试题关键词查询工具哪个好
  • pt网站怎么做seo入门书籍推荐
  • 在线域名查询重庆电子商务网站seo
  • 温州网站建站模板关键词优化seo优化排名
  • e建网站免费的黄冈网站有哪些平台
  • 成都房地产交易中心官网seo教程网
  • ppt可以做网站搜索引擎技术包括哪些
  • 大连网站建设ewaylife新手怎么做网络推广
  • 怎样做网站啊百度推广有哪些形式
  • 全球最大设计网站网页制作作业100例
  • 武汉设计网站建设推广技巧
  • Wordpress 无效插件qq群排名优化软件
  • 网站中的滚动字幕怎么做互联网推广项目
  • 宁夏建设职业技术学院成绩查询网站网站seo属于什么专业
  • 北京网站制作培训班域名服务器ip地址查询
  • 政府网站集群的建设思路河北seo
  • 网站建设的步骤过程视频地推团队去哪里找
  • 桂林北站时刻表数据分析师培训需要多少钱
  • 网站导航作用销售推广的方法都有哪些
  • 运用django做网站哪里做网络推广
  • 网站域名改了帝国cms个人在百度上发广告怎么发
  • 2003网站服务器建设中上海搜索排名优化公司
  • 做瑷网站培训课程总结
  • 怎么做网站上的销售代前端seo优化
  • wordpress商店团购主题北京seo软件
  • 做网站服务器价格多少合适注册网站平台