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

市政府网站建设网站seo优化是什么意思

市政府网站建设,网站seo优化是什么意思,discuz做企业网站,网站开发课程学习1. RTC的简介 STM32 的实时时钟(RTC)是一个独立的定时器。STM32 的 RTC 模块拥有一组连续计数的计数器,在相应软件配置下,可提供时钟日历的功能。修改计数器的值可以重新设置系统当前的时间和日期。 RTC 模块和时钟配置…

 1. RTC的简介 

STM32 的实时时钟(RTC)是一个独立的定时器。STM32 的 RTC 模块拥有一组连续计数的计数器,在相应软件配置下,可提供时钟日历的功能。修改计数器的值可以重新设置系统当前的时间和日期。
        RTC 模块和时钟配置系统(RCC_BDCR 寄存器)是在后备区域,即在系统复位或从待机模式唤醒后 RTC 的设置和时间维持不变。但是在系统复位后,会自动禁止访问后备寄存器和 RTC,以防止对后备区域(BKP)的意外写操作。所以在要设置时间之前, 先要取消备份区域(BKP)写保护。


 2. RTC的框图

这里用的是STM32其实与GD都是差不多。

 RTC 由两个主要部分组成 第一部分(APB1 接口),第二部分是后备区域。

 RT_DIV寄存器设置可编程产生 1 秒的 RTC 时间基准 TR_CLK。每一秒到来RTC_CNT

寄存器的值就会加1。RTC_CNT是32位的寄存器。1秒到还可以产生中断。以及溢出中断。以及闹钟中断。(当RTC_ALR寄存器与RTC_CNT一样)。

我们通过读取RTC_CNT的大小(多少秒)然后转换成实时时钟(年,月,日,时,分,秒)

如果我要设置一个实时时钟转成秒然后设置到RTC_CNT。

不管是设置与获取都是操作RTC_CNT并且单位是秒。具体怎么转成实时时钟要自己写逻辑。

实时时钟都是以1970年1月1日00 :00:00为开始。(红色字是重点)

由于RTC_CNT是32位的,可被初始化为当前的系统时间,一个 32 位的时钟计数器,按秒钟计算,可以记录 4294967296 秒,约合 136 年左右。所以最大:1970 + 136。如果大于这个年就会溢出。

3. 代码实现

 RTC.h

#ifndef _RTC_H
#define _RTC_H#include "gd32f10x.h"
#include <stdio.h>//日期时间结构体
typedef struct{//时间uint8_t hour;uint8_t min;uint8_t sec;//日期uint16_t w_year;uint8_t w_month;uint8_t w_day;
}_calender_obj;extern _calender_obj calender;  //日期、时间结构体变量
extern uint8_t const month_table[12];void RTC_Config(void);  //RTC配置
uint8_t RTC_Init(void);    //RTC初始化
void RTC_NVIC_Config(void); //配置RTC中断uint8_t RTC_Set(uint16_t syear, uint8_t smonth, uint8_t sday, uint8_t shour, uint8_t smin, uint8_t ssec); //将设置时间转化为秒数,给到RTC_CNT
uint8_t RTC_Get(void);  //得到RTC_CNT的值并转换为日期时间
uint8_t Is_Leap_Year(uint16_t year); //判断year是否闰年
uint8_t RTC_Get_Week(uint16_t year,uint8_t month,uint8_t day);
#endif

RTC.c

#include "RTC.h"_calender_obj calender;uint8_t const table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表
uint8_t const month_table[12]={31,28,31,30,31,30,31,31,30,31,30,31};//平年月份的天数uint32_t timecount = 0;//RTC配置
void RTC_Config(void){rcu_periph_clock_enable(RCU_BKPI); //备份区域的时钟要先使能rcu_periph_clock_enable(RCU_PMU);  //电源管理时钟使能pmu_backup_write_enable();         //使能备份域访问允许bkp_deinit();                      //备份域复位rcu_osci_on(RCU_LXTAL);            //使能外部低速时钟rcu_osci_stab_wait(RCU_LXTAL);     //等待外部低速时钟稳定rcu_rtc_clock_config(RCU_RTCSRC_LXTAL); //时钟源选择rcu_periph_clock_enable(RCU_RTC); //使能RTC时钟rtc_register_sync_wait();         //等待寄存器与APB1时钟同步rtc_lwoff_wait();   //等待RTC的最后一次操作完成rtc_interrupt_enable(RTC_INT_SECOND);//使能RTC的秒中断rtc_lwoff_wait();   //等待RTC的最后一次操作完成rtc_prescaler_set(32767); /* 配置RTC_PRL的值(时钟分频) */rtc_lwoff_wait();   //等待RTC的最后一次操作完成
}//RTC初始化
uint8_t RTC_Init(void){RTC_Config();RTC_Set(2023, 8, 21, 23, 13, 15);RTC_NVIC_Config();//配置中断的优先级return 0;
}// 配置RTC的中断优先级
void RTC_NVIC_Config(void){nvic_irq_enable(RTC_IRQn, 2, 0);
}//RTC的中断服务函数
void RTC_IRQHandler(void){if(rtc_flag_get(RTC_FLAG_SECOND) != RESET){ //判断是否为秒中断rtc_flag_clear(RTC_FLAG_SECOND);RTC_Get();printf("Now time is: %d-%d-%d %d:%d:%d\r\n", calender.w_year, calender.w_month, calender.w_day, calender.hour, calender.min, calender.sec);}
}//将设置时间转化为秒数,给到RTC_CNT
uint8_t RTC_Set(uint16_t syear, uint8_t smonth, uint8_t sday, uint8_t shour, uint8_t smin, uint8_t ssec){uint32_t seccounts = 0;uint16_t temp_year = 1970;uint8_t temp_month;if(syear<1970 || syear>2099){  //设置的时间不合理return 1;}//整年的秒数while(temp_year < syear){if(Is_Leap_Year(temp_year))seccounts += 31622400; //闰年,一年的秒数  366* 24 * 60 *60else seccounts += 31536000;  //平年,一年的秒数  365* 24 * 60 *60temp_year++;}//整月的秒数smonth--;for(temp_month = 0; temp_month<smonth; temp_month++){seccounts += (uint32_t)month_table[temp_month]*86400;if(Is_Leap_Year(syear)&&temp_month==1)seccounts += 86400; //如果设置的年份是闰年,在二月这个月份要加多一天}//日、时、分、秒的处理seccounts += (uint32_t)(sday-1)*86400; //整日的秒数  24 * 60 * 60seccounts += (uint32_t)shour*3600;//小时seccounts += (uint32_t)smin*60;   //分seccounts += ssec;      //秒rtc_lwoff_wait();rtc_counter_set(seccounts);return 0;
}//得到RTC_CNT的值并转换为日期时间
uint8_t RTC_Get(void){//把timecount转换为日期时间,并赋给calenderuint32_t temp_days = timecount/86400;uint16_t temp_year = 1970;uint16_t temp_month;uint32_t temp_seconds;timecount = rtc_counter_get();//读取RTC_CNT寄存器的值//处理天数中的整年,if(temp_days>0){while(temp_days>=365){if(Is_Leap_Year(temp_year)){//如果是闰年if(temp_days>365){temp_days -= 366;}else{break;}}else{temp_days -= 365;}temp_year++;}calender.w_year = temp_year;//剩下不足一年的,再处理整月temp_month = 1; //用来临时存放月份while(temp_days >= 28){ //超过了一个月if(Is_Leap_Year(calender.w_year) && temp_month == 2){if(temp_days>=29){ //闰年的2月是29天temp_days -= 29;}else{break;}}else{if(temp_days >= month_table[temp_month-1]){//剩余的天数是不是大于temp_month这个月整月的天数temp_days -= month_table[temp_month-1];}else{break;}}temp_month++;}}calender.w_month = temp_month;calender.w_day = temp_days+1;//处理剩下的不足一天的秒数,时:分:秒temp_seconds = timecount%86400; //不足一天的秒数calender.hour = temp_seconds/3600;calender.min = (temp_seconds%3600)/60;calender.sec = temp_seconds%60;return 0;
}uint8_t Is_Leap_Year(uint16_t year){ //判断year是否闰年if(year%4 == 0){if(year%100 == 0){if(year%400 == 0)return 1;elsereturn 0;}else{return 1;}}else{return 0;}
}//获得现在是星期几
//功能描述:输入公历日期得到星期(只允许1901-2099年)
//year,month,day:公历年月日 
//返回值:星期号																						 
uint8_t RTC_Get_Week(uint16_t year,uint8_t month,uint8_t day)
{	uint16_t temp2;uint8_t yearH,yearL;yearH=year/100;	yearL=year%100; // 如果为21世纪,年份数加100  if (yearH>19)yearL+=100;// 所过闰年数只算1900年之后的  temp2=yearL+yearL/4;temp2=temp2%7; temp2=temp2+day+table_week[month-1];if (yearL%4==0&&month<3)temp2--;return(temp2%7);
}

main.c

#include "gd32f10x_eval.h"#include "LED.h"
#include "SYSTICK_DELAY.h"
#include "RTC.h"int main(){gd_eval_com_init(EVAL_COM0);    // 初始化USART0LED_Init();my_systick_config();printf("This is a RTC DEMO test.\r\n");RTC_Init();while(1){LED1_Toggle();my_systick_delay_ms(1000);	//delay 1000 ms}
}/*重写fputc*/
int fputc(int ch, FILE *f)
{usart_data_transmit(EVAL_COM0,ch);  //通过串口把ch给发送出去while(RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE));return ch;
}

通过串口工具来显示实时时钟。先设置然后在读取通过串口显示出来。

 

http://www.hkea.cn/news/436954/

相关文章:

  • 最吃香的男生十大手艺5g网络优化
  • 河源哪里做网站网络项目怎么推广
  • 网站闭关保护怎么做广州百度seo 网站推广
  • 可以在线做动图的网站近期重大新闻事件
  • 伊犁州建设局网站怎么做微信小程序
  • 做网站需要买主机那新媒体营销方式有几种
  • 网络推广seo公司seo排名的方法
  • 南山做网站多少钱百度资讯
  • 西安哪里有做网站的小学生收集的新闻10条
  • 做游戏网站有几个要素seo网站关键词优化报价
  • 蓬业东莞网站建设技术支持东莞做网站公司首选
  • 网站版式设计获客渠道有哪些
  • 今日军事新闻简短扬州seo优化
  • 国外好看的教育类网站模板下载东莞做网站最好的是哪家
  • 微擎与wordpress快速优化seo软件推广方法
  • 英文网站设计哪家好免费网站搭建
  • 网站建设公司 销量深圳谷歌seo公司
  • 新蔡哪有做网站建设的全球疫情今天最新消息
  • 怎么做平台网站百度seo报价方法
  • 帮人做网站 怎么收费怎么用网络推广
  • 网站排名优化建设百度广告投放技巧
  • 文件服务器网站搭建教程好的竞价托管公司
  • 黑龙江省城乡和住房建设厅网站首页百度链接地址
  • 网站模板修改工具专业seo关键词优化
  • 口碑好的句容网站建设yahoo搜索
  • 深圳网站建设外贸公司价格网络营销的背景和意义
  • 长春网站建设硕成传媒seo快速排名优化公司
  • web网站开发能使用c 吗免费建立个人网站申请
  • 织梦网站修改教程视频网站优化培训学校
  • 南沙区交通和建设局网站中国十大网络销售公司