求各位大神解救,此PWM无输出,已经将PD2设置了推挽输出方式,并且在optionbyte中也设置了PORT D2 alternate function=TIM2_CH3了,但是下载到芯片无输出呢,求大神帮帮忙~~
程序如下:
#include "stm8s103f.h"
void delayms(unsigned int ms)
{
unsigned char i;
while(ms!=0)
{
for(i=0;i<250;i++);
for(i=0;i<75;i++);
ms--;
}
}
void CLK_Init(void)
{
CLK_CKDIVR=0x11;
}
void TIM2_Init(void)
{
TIM2_CCMR3|=0x70;
TIM2_CCER1|=0x30;
TIM2_ARRH=0;
TIM2_ARRL=0xFF;
TIM2_CCR3H=0;
TIM2_CCR3L=0;
TIM2_PSCR=0;
TIM2_CR1|=0x01;
}
main()
{
unsigned char i;
PD_DDR=0x04;
PD_CR1=0x04;
PD_CR2=0x00;
CLK_Init();
TIM2_Init();
while(1)
{
for(i=0;i<128;i++)
{
TIM2_CCR3H=0;
TIM2_CCR3L=i;
delayms(5);
}
for(i=128;i>0;i--)
{
TIM2_CCR3H=0;
TIM2_CCR3L=i;
delayms(5);
}
}
} |