栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【无标题】大佬帮我看下stm32呼吸灯为啥不闪

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【无标题】大佬帮我看下stm32呼吸灯为啥不闪

#include "stm32f10x.h"
#include "Delay.h"
#include "stm32f10x_tim.h"
//#include "Encoder.h"
//#include "OLED.h"
     static u16 i=0;
          u8 Flag=1;
        
void TIMCH_UserConfig(u16 Period,u16 Prescaler ){
    GPIO_InitTypeDef GPIO_InitStructure;
    TIM_TimebaseInitTypeDef TIM_InitStructure;
    TIM_OCInitTypeDef PWM_InitStructure;
    
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
    
    GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&GPIO_InitStructure);
    
    TIM_InitStructure.TIM_Period=Period;  //重载值 
    TIM_InitStructure.TIM_Prescaler=Prescaler; //预分频
    TIM_InitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
    TIM_InitStructure.TIM_RepetitionCounter=DISABLE;
    TIM_InitStructure.TIM_CounterMode=TIM_CounterMode_Up;
    TIM_TimebaseInit(TIM2,&TIM_InitStructure);
    
    PWM_InitStructure.TIM_OCMode=TIM_OCMode_PWM1;
    PWM_InitStructure.TIM_OutputState=TIM_OutputState_Enable;
    PWM_InitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
    TIM_OC1Init(TIM2,&PWM_InitStructure);
    
    TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);
    TIM_Cmd(TIM2,ENABLE);

}
 void TIMCH_PWM(void){
     if(Flag==1)
     {
         i++;
     }
      else
     {
        i--; 
     }
     if(i>899)Flag=0;
     
     if(i==0)Flag=1;
  TIM_SetCompare1(TIM2,i);
     
     }

     #include "stm32f10x.h"              
#include "Delay.h"
#include "OLED.h"
#include "Encoder.h"
#include "timch.h"
#include "LED.h "
#include "stm32f10x_tim.h" 
int16_t Num;
  
int main(void)
{
    SystemInit();
    
    TIMCH_UserConfig(899,0 );
    
    while (1)
    {
         TIMCH_PWM();
        
        
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/665291.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号