stm32f103 time2配置,转载
//----------------------------main()-------------------- //stm32f103c8t6有3个普通1个高级定时器
//每次进入中断服务程序间隔时间为
//((1+TIM_Prescaler )/72M)*(1+TIM_Period )=((1+7199)/72M)*(1+9999)=1秒
#include<stm32f10x.h>
#define D13_ON GPIO_ResetBits(GPIOC,GPIO_Pin_13)
#define D13_OFF GPIO_SetBits(GPIOC,GPIO_Pin_13) void GPIO_Config(void);
void TIM2_Config(u16 arr,u16 psc);
void NVIC_Config(void); //主函数
int main(void)
{
GPIO_Config();
//((1+arr )/72M)*(1+psc )=((1+1999)/72M)*(1+35999)=1秒
TIM2_Config(1999,35999);
NVIC_Config();
while(1); } //初始化GPIO
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //PC13灯
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_ResetBits(GPIOC,GPIO_Pin_13); //关闭LED
} //初始化TIM2定时器及中断
//每次进入中断服务程序间隔时间为
//((1+arr )/72M)*(1+psc )=((1+1999)/72M)*(1+35999)=1秒
void TIM2_Config(u16 arr,u16 psc)
{
//定时器时间是1s TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
//清除中断标志位
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);//TIM_ClearFlag(TIM2,TIM_FLAG_Update);//两者作用相同 //自动装载的周期值0-0xffff,72M/36000=2000
TIM_TimeBaseStructure.TIM_Period = arr;
//时钟除数预分频值0-oxffff,下面是36000分频
TIM_TimeBaseStructure.TIM_Prescaler = psc;
////普通和高级才有下面两行
//时钟分割,暂时为0,高级应用才用
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
//计数模式,向上下,中央对齐123
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure); //开启中断
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
//开启外设
TIM_Cmd(TIM2,ENABLE);
} //初始化中断向量控制器NVIC void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} //--------------------stm32f10x_it.c------------------------
//中断函数中自己编写
void TIM2_IRQHandler(void)
{
//判断TIM3更新中断是否发生
if(TIM_GetITStatus(TIM2,TIM_IT_Update)!=RESET)
{
//必须清楚标志位
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
//状态取反
GPIO_WriteBit(GPIOC,GPIO_Pin_13,(BitAction)(!GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_13)));
} }
---------------------
作者:sea1216
来源:CSDN
原文:https://blog.csdn.net/sea1216/article/details/80621489
版权声明:本文为博主原创文章,转载请附上博文链接!
stm32f103 time2配置,转载的更多相关文章
- git在eclipse中的配置 转载
git在eclipse中的配置 转载 一_安装EGIT插件 http://download.eclipse.org/egit/updates/ 或者使用Eclipse Marketplace,搜索EG ...
- Sublime Text 2 配置(转载)
转载 自 Sublime Text 2 的详细配置(C++) 想起暑假在公司偷偷写题,用不惯vs ,配sublime 又一直编译不了...每次用codeblocks 眼泪掉下来www 下载sublim ...
- 史上最详细Windows版本搭建安装React Native环境配置 转载,比官网的靠谱亲测可用
史上最详细Windows版本搭建安装React Native环境配置 2016/01/29 | React Native技术文章 | Sky丶清| 95条评论 | 33530 views ...
- Apache+tomcat+mod_jk+centos6.2负载均衡集群配置--转载
转载地址:http://blog.163.com/chenhui_java/blog/static/17267249420128101191860/ 注: 由于长期受转载毒害,所以本人日志均是原创:其 ...
- window xp Apache与Tomcat集群配置--转载
转载地址:http://www.cnblogs.com/obullxl/archive/2011/06/09/apache-tomcat-cluster-config.html 一. 环境说明 Win ...
- Apache Kafka 分布式消息队列中间件安装与配置 转载
bin/zkServer.sh start /home/guym/down/kafka_2.8.0-0.8.0/config/zookeeper.properties& bin/kafka-s ...
- windows 安装 Apache、php、mysql及其配置(转载)
此文包括的注意内容:软件版本及下载地址Apache2.4的配置和安装php7.0的配置mysql5.5的安装常见问题及解决方法1.软件版本Windows server 2008 r2+ 64位Apac ...
- Windows下Mongodb安装及配置(转载)
转载(https://blog.csdn.net/liang377122210/article/details/79062681) MongoDB的安装很简单,设置好安装路径后,一直Next直到安装结 ...
- Linux NFS服务器的安装与配置(转载)
一.NFS服务简介 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操 ...
随机推荐
- tcp/ip 调优示例
# Kernel sysctl configuration file for Linux # # Version 1.12 - 2015-09-30 # Michiel Klaver - IT Pro ...
- ORACLE_DELETE
SQL DELETE Statement The SQL DELETE Statement The DELETE statement is used to delete existing record ...
- thinkphp5设置403 404等http状态页面
在thinkphp5中如何抛出异常状态码(比如401,403,404等),因为这些能极大的给用户以良好的体验. 因为在上线阶段,任何的系统错误信息都不能让浏览用户给看到,比如404(Not Found ...
- 原文:I don’t want to see another “using namespace xxx;” in a header file ever again
http://stackoverflow.com/questions/5849457/using-namespace-in-c-headers http://stackoverflow.com/que ...
- 我的HTML总结之常用基础便签
HTML:是Hyper Text Markup Language(超级文本标记语言)的缩写,HTML不是一种程序,只是一种控制网页中数据显示的标识语言. HTML由一组标签组成. HTML的基本结构 ...
- Reverse Polish notation
Reverse Polish notation is a notation where every operator follows all of its operands. For example, ...
- html5中event获取data和class
获取data和class var tare=$(e.relatedTarget).data("id");var tar=event.target;console.log(tare) ...
- 【luogu P1807 最长路_NOI导刊2010提高(07)】 题解
题目链接:https://www.luogu.org/problemnew/show/P1807 求最大路?就是把权值取相反数跑最短路. #include <cstdio> #includ ...
- java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content&q ...
- lucene&solr学习——创建和查询索引(代码篇)
1. Lucene的下载 Lucene是开发全文检索功能的工具包,从官网下载Lucene4.10.3并解压. 官网:http://lucene.apache.org/ 版本:lucene7.7.0 ( ...