//占空比50%
#include "stm8s.h"
void main(void)
{
//系统时钟切换配置(自动切换,外部高速晶振,关闭切换中断,
CLK_ClockSwitchConfig (CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE,
//切换后关闭旧的时钟源)
DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE );
//TIM1复位
TIM1_DeInit();
//16 MHz/16 分频= 1 兆赫、向上计数, 1 MHz /1000 =计数 1000
TIM1_TimeBaseInit( 15, TIM1_COUNTERMODE_UP, 1000, 0 );
//初始化捕获/比较通道1(PWM模式1,启用输出比较),
TIM1_OC1Init( TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE,
//启用互补输出比较1,脉宽50%,输出比较极性高电平,
TIM1_OUTPUTNSTATE_ENABLE, 500, TIM1_OCPOLARITY_HIGH,
//互补输出比较极性高电平,输出比较空闲状态复位,互补输出比较空闲状态复//位)
TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_SET );
//TIM1_BDTRConfig( TIM1_OSSISTATE_ENABLE, TIM1_LOCKLEVEL_OFF, 0xff, TIM1_BREAK_DISABLE, TIM1_BREAKPOLARITY_LOW, TIM1_AUTOMATICOUTPUT_ENABLE);
//启用定时器
TIM1_Cmd(ENABLE);
//允许主输出 移动 TIM1 定时器。选择 PWM 输出。
TIM1_CtrlPWMOutputs(ENABLE);
while(1) { } // main loop
}
#ifdef USE_FULL_ASSERT
void assert_failed(u8* file, u32 line)
{
while (1) { }
}
#endif |