STM32F4|STM32F4 TIM6 TIM7 基本定时器
以下为 TIM.C
#include "tim.h"
#include "led.h"
#include "usart.h"void TIM6_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);
TIM_TimeBaseInitStructure.TIM_Period = arr;
TIM_TimeBaseInitStructure.TIM_Prescaler=psc;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM6,&TIM_TimeBaseInitStructure);
TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM6,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel=TIM6_DAC_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x03;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM7_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7,ENABLE);
TIM_TimeBaseInitStructure.TIM_Period = arr;
TIM_TimeBaseInitStructure.TIM_Prescaler=psc;
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM7,&TIM_TimeBaseInitStructure);
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM7,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel=TIM6_DAC_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x03;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}void TIM6_DAC_IRQHandler(void)
{
if(TIM_GetITStatus(TIM6,TIM_IT_Update)==SET)
{
GPIO_ToggleBits(GPIOF,GPIO_Pin_9 );
TIM_ClearITPendingBit(TIM6,TIM_IT_Update);
}if(TIM_GetITStatus(TIM7,TIM_IT_Update)==SET)
{
GPIO_ToggleBits(GPIOF,GPIO_Pin_10);
TIM_ClearITPendingBit(TIM7,TIM_IT_Update);
}}
以下为 tim.h
#ifndef _TIMER_H
#define _TIMER_H
#include "sys.h"void TIM6_Int_Init(u16 arr,u16 psc);
void TIM7_Int_Init(u16 arr,u16 psc);
#endif
主函数进行初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
LED_Init();
TIM6_Int_Init(5000-1,8400-1);
TIM7_Int_Init(10000-1,8400-1);
推荐阅读
- UCOS II 移植到STM32F407
- STM32F407因为结构体字节对齐导致的HardFault_Handler异常
- stm32F4 配置串口+DMA 接收不定长数据 串口空闲中断
- stm32f429i|stm32f429i disc usb cdc vcp 虚拟串口 example project (CubeMX Hal)
- 基于STM32F429+HAL库编写的定时器主从门控模式级联输出固定个数PWM脉冲的程序
- STM32F407VG uCOS-II2.91 IAR工程 以及uCOS使用库编译的方法
- uCOS|8.uCOS3在STM32F4开发板上的移植
- 使用stm32F407或者F103进行UCOS操作系统的移植|使用stm32F407或者F103进行UCOS操作系统的移植 嵌入式开发报告
- STM32F4Ucosii环境LWIP移植
- STM32F4_UCOSIII|STM32F4_UCOSIII esp8266_free_rtos 双机SPI通信