搁置

// 输出灯完成不亮,目前没有找到问题,搁置待细细查看


#include "stm32f4xx.h"


void delay();
void pwm_init(u32 arr,u32 pre);  // pwm¿ØÖƵƵÄÁÁ°µ

int main(){
u16 led0val=0;
u8 dir=1;
delay();

pwm_init(500-1,84-1);

while(1){
delay();
if(dir) led0val++;
else led0val--;
if(led0val>300)
dir=0;
if(led0val==0)
dir=1;

TIM_SetCompare1(TIM14,led0val);
}

}
void delay(){
int i,j;
for(i=0;i<1000;i++)
for(j=0;j<1000;j++)
{}
}

void pwm_init(u32 arr,u32 pre){ //pwmÕâÀïÓõ½µÄÊÇTIM14µÄͨµÀ1£¬½øÐⶻñ£¬PF9¸´Óõ½TIM14ÉÏ
GPIO_InitTypeDef GPIO_InitStruct;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14,ENABLE);

GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;

GPIO_Init( GPIOF,  &GPIO_InitStruct);
GPIO_PinAFConfig( GPIOF,GPIO_PinSource9,GPIO_AF_TIM14);
// GPIO_ResetBits(GPIOF,  GPIO_Pin_9);

TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;  
TIM_TimeBaseInitStruct.TIM_Period=arr;
TIM_TimeBaseInitStruct.TIM_Prescaler=pre;

TIM_TimeBaseInit( TIM14, &TIM_TimeBaseInitStruct);

TIM_OCInitStruct.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OCPolarity=TIM_OCPolarity_Low;
TIM_OCInitStruct.TIM_OutputState=TIM_OutputState_Enable;

TIM_OC1Init( TIM14, &TIM_OCInitStruct);


TIM_OC1PreloadConfig( TIM14, TIM_OCPreload_Enable );
TIM_ARRPreloadConfig( TIM14, ENABLE );  


TIM_Cmd( TIM14,  ENABLE);

//TIM_ITConfig( TIM14,  TIM_IT_Update,  ENABLE);  
}









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一枚努力的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值