stm8s005k6 单片机 tim2 ch2 无法输出PWM,请给一个基本的程序,感谢,弄了很久... 20
在stm8s003上可以用的程序,移值到stm8s005上无法运行.voidTIM2_init(void)//{TIM2_PSCR=0x0;TIM2_CCMR1=TIM2...
在stm8s003 上可以用的程序,移值到stm8s005 上无法运行.
void TIM2_init(void)//
{
TIM2_PSCR =0x0;
TIM2_CCMR1 = TIM2_CCMR1 | 0x70;//
TIM2_CCER1 = TIM2_CCER1 | 0x03; //
TIM2_ARRH = 0x03; //
TIM2_ARRL = 0xFF; //
TIM2_CCR2H=0x01;
TIM2_CCR2L=0xff;
TIM2_CR1 |= 0x01; // 计数器使能,开始计数
}
/************************************************************************/
void main(void)
{
CLK_CKDIVR = 0x00;
TIM2_init();
while(1);
} 展开
void TIM2_init(void)//
{
TIM2_PSCR =0x0;
TIM2_CCMR1 = TIM2_CCMR1 | 0x70;//
TIM2_CCER1 = TIM2_CCER1 | 0x03; //
TIM2_ARRH = 0x03; //
TIM2_ARRL = 0xFF; //
TIM2_CCR2H=0x01;
TIM2_CCR2L=0xff;
TIM2_CR1 |= 0x01; // 计数器使能,开始计数
}
/************************************************************************/
void main(void)
{
CLK_CKDIVR = 0x00;
TIM2_init();
while(1);
} 展开
3个回答
展开全部
不是可以直接调用库文件吗?
TIM1_DeInit();
//设置死区时间10/16=0.6us
TIM1_BDTRConfig(TIM1_OSSISTATE_ENABLE,TIM1_LOCKLEVEL_OFF,10,TIM1_BREAK_DISABLE,
TIM1_BREAKPOLARITY_LOW,TIM1_AUTOMATICOUTPUT_DISABLE);
//设置PWM频率10K
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 100*16, 0); //100us 10K
//PWM极性设置相同,则输出为互补,否则为同步信号。
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);
TIM1_ARRPreloadConfig(ENABLE);
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_DeInit();
//设置死区时间10/16=0.6us
TIM1_BDTRConfig(TIM1_OSSISTATE_ENABLE,TIM1_LOCKLEVEL_OFF,10,TIM1_BREAK_DISABLE,
TIM1_BREAKPOLARITY_LOW,TIM1_AUTOMATICOUTPUT_DISABLE);
//设置PWM频率10K
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 100*16, 0); //100us 10K
//PWM极性设置相同,则输出为互补,否则为同步信号。
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_DISABLE,
PulseWidth, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH,
TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);
TIM1_ARRPreloadConfig(ENABLE);
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
追问
一直没有用过库文件,主要是看不懂,觉的自已写提令比较通用一点. 能帮我写一个能运行程序吗?多谢
追答
不好意思我都是调用库来写的!上面程序是可以实现的,你要么就对照库文件看看吧!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询