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 |
来点注释就好了 |
从零开始操作STM8寄存器(风驰iCreate奉献)
【中文资料】初学STM8库函数的中文帮助软件
绝对经典的中文STM8学习手册,淘宝上学习板资料,友情大放送!
【原创教程】风驰iCreate独家开源STM8 27个例程和10多万字的pdf教程
STM8的LCD1602 4线驱动,为什么不工作
【精华资料】由零开始开发STM8
STM8S 的触摸库是如何在主程序中查询键的呢、
【精华资料】STM8的C语言编程1-14讲完整版
【精品教程】STM8系列单片机入门教程系列
STM8 第一次进中断不准【悬赏问答】