集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 779|回复: 1

定时器控制LED灯闪烁

[复制链接]
zxopenluyutong 发表于 2021-5-17 09:25:03 | 显示全部楼层 |阅读模式
#include <sys.h>
#include <led.h>
#include <TIM1.h>

int main(void)
{
        NVIC_Configuration();
        Led_init();
        TIM1_Init();
       
        while(1)
        {
       
        }

}
void TIM1_UP_IRQHandler  (void)
{
       
        TIM_ClearFlag(TIM1,TIM_FLAG_Update);
        LED=~LED;

}
#include <led.h>
//PC13

void Led_init(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
        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);
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
#include <TIM1.h>



void TIM1_Init(void)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        //使能定时器1时钟
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = (10000-1);//ARR
        TIM_TimeBaseStructure.TIM_Prescaler = (7200-1);//PSC
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);

//使能定时器1的中断
        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
//配置定时器1的中断优先等级       
        NVIC_InitStructure.NVIC_IRQChannel =TIM1_UP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
//使能定时器1
        TIM_Cmd(TIM1,ENABLE);
       
}
zhangyukun 发表于 2021-5-17 09:35:26 | 显示全部楼层
定时器控制LED灯闪烁
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-11-29 01:45 , Processed in 0.057489 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表