#include"
STM32f10x.h"
#include"stm32f10x_gpio.h"
#include"stm32f10x_rcc.h"
#include"stm32f10x_
tim.h"
#include"delay.h"
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
void TIM3_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIMEBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE);
TIMEBaseInitStructure.TIM_Period=19999;
TIMEBaseInitStructure.TIM_Prescaler=0;
TIMEBaseInitStructure.TIM_ClockDivision=0;
TIMEBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3,&TIMEBaseInitStructure);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC1Init(TIM3,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_Cmd(TIM3,ENABLE);
}
int main(void)
{
u8 led_fx=1;
u32 led_dt=1;
RCC_Configuration();
GPIO_Configuration();
TIM3_Configuration();
while(1)
{
if(led_fx==1)
{
led_dt+=5;
}
else
{
led_dt-=5;
}
if(led_dt>1000) led_fx=0;
if(led_dt==0) led_fx=1;
TIM_SetCompare2(TIM3,led_dt);
}
}
不知道哪里不对,能不能帮我看看
一周热门 更多>