stm8s003用tim1_ch2输出pwm 一直无法输出
/* 添加库函数头文件 */
#include "stm8s.h"
//数码管0 ~ F的代码数组
//u8 const Data[16] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void Init_pwm()
{
GPIO_Init(GPIOC, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST); //输出推拉,低电平,10MHz
TIM1_DeInit();
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 800, 0x00);//250
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 400,
TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_RESET);//50%占空比
TIM1_CCxCmd(TIM1_CHANNEL_2, ENABLE);
TIM1_OC2PreloadConfig(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE); //TIM1输出使能
TIM1_Cmd(ENABLE);//TIM1使能
//TIM1->CCER1 |= 0x10; //开启OC2信号输出脚
// TIM1->CCMR2 = 0x60; //PWM1模式
// TIM1->CCR2H = 0x00; //占空比高位
//TIM1->CCR2L = 0x37; //占空比低位
// TIM1->CCMR2 |= 0x08; //输出比较2预装载使能
}
void assert_failed(u8* file, u32 line)
{
while (1)
{
}
}
void main(void)
{
//CLK_DeInit();//初始化clk相关寄存器为初始值
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //内部时钟16M
Init_pwm();
enableInterrupts();
while(1);
}
|