stm8s105c6 定时器2 通道2 PWM 怎么搞都不能输出,朋友们帮我看看,谢谢了! (基于IAR)
//实验板STM8S_DISCOVERY
//STM8 IAR C
/* Includes ------------------------------------------------------------------*/
#include "iostm8s105c6.h"
/* Global variables ----------------------------------------------------------*/
void CLK_Configuration(void)
{
CLK_CKDIVR = 0x05; /* 主时钟初使化 */
}
void GPIO_Init(void)
{
PD_DDR |= 0x04; //端口初使化
PD_CR1 |= 0x04;
PD_CR2 = 0x00;
}
void TIM2_PWM(void)
{
TIM2_CCMR2= 0x70; //通道2被设置成比较输出方式,OC2M = 111,为PWM模式2
TIM2_CCER1= 0x30; // CC2E = 1,开启输出引脚 CC2P = 1,低电平为有效电平
TIM2_ARRH = 0x00; //PWM 频率调节
TIM2_ARRL = 0xFF;
TIM2_CCR2H= 0xff; //占空比调节
TIM2_CCR2L= 0xff;
TIM2_PSCR = 0x00; //4位可编程(可以实时修改的)预分频器=.
// TIM1_CNTRH = 0x00; //计数器高位
// TIM1_CNTRL = 0x7F;
TIM1_CR1 |= 0x01; // 1.缓冲 2.使能计数器
}
main()
{
CLK_Configuration();
// GPIO_Init();
TIM2_PWM();
while (1)
{
asm("nop");
asm("nop");
asm("nop");
}
} |