STM32f103 —— timer
来源:互联网 发布:大众点评张涛编程 编辑:程序博客网 时间:2024/05/16 07:21
#ifndef _TIMER_H_#define _TIMER_H_#include "stm32f10x.h"#include "type.h"// LED定时器,按键定时器,重发定时器#define LED_TIMER TIM1#define LED_TIMER_DIV 7200#define LED_TIMER_PERIOD 2500#define PWM_TIMER TIM2#define RESEND_TIMER TIM3#define RESEND_TIMER_DIV 7200 #define RESEND_TIMER_PERIOD 2500#define KEY_TIMER TIM4#define KEY_TIMER_DIV 7200#define KEY_TIMER_PERIOD 200void TimerNvicConfig(void);void TimerConfig(TIM_TypeDef *timer, uint16_t div, uint16_t period);void TimerEnable(TIM_TypeDef *timer);void TimerDisable(TIM_TypeDef *timer);#endif /* _TIMER_H_ */#include "stm32f10x_tim.h"#include "stm32f10x_rcc.h"#include "timer.h"/** 三个定时器: 1 灯色 2 按键 3 重发*/void TimerNvicConfig(void){ NVIC_InitTypeDef NVIC_StructInit; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); NVIC_StructInit.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_StructInit.NVIC_IRQChannelCmd = ENABLE; NVIC_StructInit.NVIC_IRQChannelPreemptionPriority = 0; NVIC_StructInit.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_StructInit); NVIC_StructInit.NVIC_IRQChannel = TIM2_IRQn; NVIC_StructInit.NVIC_IRQChannelCmd = ENABLE; NVIC_StructInit.NVIC_IRQChannelPreemptionPriority = 1; NVIC_StructInit.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_StructInit); NVIC_StructInit.NVIC_IRQChannel = TIM3_IRQn; NVIC_StructInit.NVIC_IRQChannelCmd = ENABLE; NVIC_StructInit.NVIC_IRQChannelPreemptionPriority = 2; NVIC_StructInit.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_StructInit); NVIC_StructInit.NVIC_IRQChannel = TIM4_IRQn; NVIC_StructInit.NVIC_IRQChannelCmd = ENABLE; NVIC_StructInit.NVIC_IRQChannelPreemptionPriority = 3; NVIC_StructInit.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_StructInit);}void TimerConfig(TIM_TypeDef *timer, uint16_t div, uint16_t period){ TIM_TimeBaseInitTypeDef TIM_StructInit; if(LED_TIMER == timer) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); } else if(RESEND_TIMER == timer) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); } else if(KEY_TIMER == timer) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); } TIM_StructInit.TIM_Period = period; TIM_StructInit.TIM_Prescaler = div; TIM_StructInit.TIM_ClockDivision = TIM_CKD_DIV1; /* 数字滤波器采样频率 */ TIM_StructInit.TIM_CounterMode = TIM_CounterMode_Up; /* 向上计数 */ TIM_StructInit.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(timer, &TIM_StructInit); TIM_ITConfig(timer, TIM_IT_Update, ENABLE); /* 允许中断 */ TIM_ClearFlag(timer, TIM_FLAG_Update); /* 更新定时器会产生更新时间,清除标志位 */}void TimerEnable(TIM_TypeDef *timer){ TIM_Cmd(timer, ENABLE);}void TimerDisable(TIM_TypeDef *timer){ TIM_Cmd(timer, DISABLE);}
0 0
- STM32f103 —— timer
- STM32f103——ILI9341
- STM32f103 —— can通信
- stm32f103学习笔记——NVIC初始化
- STM32F103学习笔记——仿真波形
- STM32F103学习笔记——SysTick
- STM32F103学习笔记——外部中断
- STM32F103学习笔记——串口通信
- STM32f103 —— 内部flash读写
- 【stm32f103】TIMER基本定时功能的使用(寄存器版)
- STM32F103
- erlang——timer
- iOS——timer
- 驱动程序——MAX6675——基于STM32F103
- 驱动程序——MCP4922——基于STM32F103
- 驱动程序——TLC7226——基于STM32F103
- 1.STM32F103学习——GPIO之点亮小灯
- stm32f103学习笔记——关键字extern、static、const
- 利用Eclipse调试Wowza模块(Debug模式)
- Junit之断言测试
- iOS10 经过yalu越狱后无法ssh登录和无法scp拷贝问题
- String,StringBuffer与StringBuilder的区别??
- 图像处理--RGB到HSI的彩色转换--图像分割(MFC VC++)
- STM32f103 —— timer
- class.getResource()和getResourceAsStream用法
- ES6 Proxy
- Transport Protocols and Mechanisms in JavaMail
- Android应用开发中三种常见的图片压缩方法
- Yii2 开源商城 FecShop
- NOIP 2001 普及组 复赛 数的计算
- centos7 php7.1.2编译安装
- markdown中划线