步骤
1.初始化时钟
2.初始化Io口
3.初始化定时器
4.初始化pwm输出通道
1、初始化时钟
void rcc_periph_clock_enable(void)
{
//启动GPIOA时钟
rcu_periph_clock_enable(RCU_GPIOA);
//启动TUME0时钟
rcu_periph_clock_enable(RCU_TIMER0);
}
2.初始化Io口
void GPIO_MOde_init(void)
{
//设置引脚模式
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_8);
gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0);
//设置输出频率
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_8);
//设置初始电平状态
gpio_bit_reset(GPIOA,GPIO_PIN_8);
//设置引脚复用哪个功能,这里设置为PWM
gpio_af_set(GPIOA,GPIO_AF_2, GPIO_PIN_8);
}
3.初始化定时器
void Timer_initstructure(void)
{
//定义定时器1结构体变量
timer_parameter_struct timer0_initpara;
timer_oc_parameter_struct timer_initpara;
//设置定时器1为缺省值
timer_deinit(TIMER0);
//注意!当你实用timer0高级定时器的时候必须使能这个,才能有pwm输出
timer_primary_output_config(TIMER0,ENABLE);
/* TIMER1 初始化配置 */
/*
prescaler: prescaler value of the counter clock, 0~65535
alignedmode: TIMER_COUNTER_EDGE, TIMER_COUNTER_CENTER_DOWN, TIMER_COUNTER_CENTER_UP, TIMER_COUNTER_CENTER_BOTH
counterdirection: TIMER_COUNTER_UP, TIMER_COUNTER_DOWN
period: counter auto reload value, 0~65535
clockdivision: TIMER_CKDIV_DIV1, TIMER_CKDIV_DIV2, TIMER_CKDIV_DIV4
repetitioncounter: counter repetition value, 0~255
*/
timer0_initpara.prescaler = BASIC_TIM_Prescaler;/*!< prescaler value */
timer0_initpara.alignedmode = TIMER_COUNTER_EDGE;/*!< aligned mode */
timer0_initpara.counterdirection = TIMER_COUNTER_UP;/*!< counter direction */
timer0_initpara.clockdivision = TIMER_CKDIV_DIV1;/*!< clock division value */
timer0_initpara.period = BASIC_TIM_Period;/*!< period value */
timer0_initpara.repetitioncounter = 0;/*!< the counter repetition value */
//初始化定时器
timer_init(TIMER0,&timer0_initpara);
/* CH1,CH2 and CH3 configuration in PWM mode1 */
/*
TIMER channeln output parameter struct
outputstate: TIMER_CCX_ENABLE,TIMER_CCX_DISABLE
outputnstate: TIMER_CCXN_ENABLE,TIMER_CCXN_DISABLE
ocpolarity: TIMER_OC_POLARITY_HIGH,TIMER_OC_POLARITY_LOW
ocnpolarity: TIMER_OCN_POLARITY_HIGH,TIMER_OCN_POLARITY_LOW
ocidlestate: TIMER_OC_IDLE_STATE_LOW,TIMER_OC_IDLE_STATE_HIGH
ocnidlestate: TIMER_OCN_IDLE_STATE_LOW,TIMER_OCN_IDLE_STATE_HIGH
*/
//是否使能输出
timer_initpara.outputstate = TIMER_CCX_ENABLE;
//是否互补通道输出
timer_initpara.outputnstate = TIMER_CCXN_DISABLE;
//输出极性
timer_initpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
//输出死区延迟的极性
timer_initpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
//空闲状态下通道输出极性通道
timer_initpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
//空闲时互补通道输出极性
timer_initpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
//配置通道
timer_channel_output_config(TIMER0,TIMER_CH_0,&timer_initpara);
//*!!!!设置阈值(比较值,调节占空比的时候调节这个值)
timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_0,00);
//输出模式配置
timer_channel_output_mode_config(TIMER0,TIMER_CH_0,TIMER_OC_MODE_PWM0);
//不使用影子寄存器
timer_channel_output_shadow_config(TIMER0,TIMER_CH_0,TIMER_OC_SHADOW_DISABLE);
/* 使能定时器自动重装载值 */
timer_auto_reload_shadow_enable(TIMER0);
/* 使能定时器 */
timer_enable(TIMER0);
}
Dear immortals, I need some wow gold inspiration to create.
Ahora que muchas personas usan teléfonos inteligentes, podemos considerar el posicionamiento de teléfonos móviles a través de redes inalámbricas o estaciones base. https://www.xtmove.com/es/how-to-track-location-of-someone-phone-without-their-knowledge/
877572 199326really nice publish, i definitely love this web website, keep on it 525544
You can also customize monitoring for certain apps, and it will immediately start capturing phone screen snapshots regularly.
bahis siteleri porn sex incest tthighereduhryyy.m0Qx8TDJjVR
125511 658385You got a really excellent internet site, Glad I noticed it by way of yahoo. 912266
938977 28508This kind of publish appears to get yourself plenty of visitors. How will you acquire traffic to that? It provides a terrific distinctive twist upon issues. I guess having something traditional or maybe substantial to give info on is the central aspect. 731022
488220 842997Glad to be one of the visitors on this awe inspiring internet site : D. 500866
Wow, incredible blog structure! How lengthy have you ever been blogging for?
you make blogging look easy. The overall look of your website is great, as smartly as the content material!
You can see similar here sklep internetowy
Wow, awesome weblog layout! How long have you
been running a blog for? you make running a blog look easy.
The whole look of your website is magnificent, as smartly as the content!
You can see similar here e-commerce
852071 591956Youll uncover some fascinating points in time in this post but I do not know if I see all of them center to heart. Theres some validity but I will take hold opinion until I appear into it further. Great post , thanks and we want a lot more! Added to FeedBurner too 797983