在线时间0 小时
UID245354
ST金币0
蝴蝶豆0
注册时间2007-6-13
新手上路
- 最后登录
- 2019-8-1
|
a0a.1 0b0c
TIMx_OCMODE_TOGGLE //此模式或产生任意频率的50%占空比方波 (FOSC/分频系数)/(2*TIM2_Period)
TIMx_OCMODE_PWM1 //PWM模式可设置PWM一周期的时钟数,并调可节占空比
<div class="dp-highlighter">view plaincopy to clipboardprint?
<ol start="1" class="dp-c"> <li class="alt">#include "stm8s.h" #include "stm8s_tim2.h"
<li class="alt">#include "stm8s_tim3.h" u16 CCR1_Val = 300;
<li class="alt">u16 CCR2_Val = 100; u16 CCR3_Val = 100;
<li class="alt">void main(void) {
<li class="alt"> CLK_HSECmd(ENABLE);//外部时钟开 CLK_LSICmd(ENABLE);//使能内部低频RC
<li class="alt"> CLK_HSICmd(ENABLE);//使能内部高频RC CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);//内部高速RC振荡时钟分频
<li class="alt"> CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);//CPU核心时钟分频 CLK_ClockSwitchCmd(ENABLE); //切换使能
<li class="alt"> CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO ,CLK_SOURCE_HSE,DISABLE,CLK_CURRENTCLOCKSTATE_DISABLE);//切换配置
<li class="alt"> TIM3_TimeBaseInit(TIM3_PRESCALER_1, 1024);
<li class="alt"> TIM3_OC1Init(TIM3_OCMODE_TOGGLE, TIM3_OUTPUTSTATE_ENABLE,CCR1_Val, TIM3_OCPOLARITY_HIGH);//此模式或产生任意频率的50%占空比方波 (FOSC/分频系数)/(2*TIM2_Period) TIM3_OC1PreloadConfig(ENABLE);
<li class="alt"> TIM3_OC2Init(TIM3_OCMODE_TOGGLE, TIM3_OUTPUTSTATE_ENABLE,CCR1_Val, TIM3_OCPOLARITY_HIGH);//此模式或产生任意频率的50%占空比方波 (FOSC/分频系数)/(2*TIM2_Period)
<li class="alt"> TIM3_OC2PreloadConfig(ENABLE);
<li class="alt"> TIM3_ARRPreloadConfig(ENABLE); TIM3_Cmd(ENABLE);
<li class="alt"> /* Time base configuration */
<li class="alt"> TIM2_TimeBaseInit(TIM2_PRESCALER_1, 1024); TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH);//PWM模式可设置PWM一周期的时钟数,并调可节占空比
<li class="alt"> TIM2_OC1PreloadConfig(ENABLE);
<li class="alt"> TIM2_OC2Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH);//PWM模式可设置PWM一周期的时钟数,并调可节占空比 TIM2_OC2PreloadConfig(ENABLE);
<li class="alt"> TIM2_ARRPreloadConfig(ENABLE); TIM2_Cmd(ENABLE);
<li class="alt"> while (1)
<li class="alt"> { DelayUs(1000);
<li class="alt"> if(CCR1_Val |
|