在线时间0 小时
UID411255
ST金币0
蝴蝶豆0
注册时间2013-1-8
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
STM8L 使用discovery板输出PWM到LED的问题
我想用PWM(PD2)输出模拟信号到LED(PE7),实现LED的逐渐变亮(暗),
可是不成功,各位高手给指出错误吧,谢谢
void main(void)
{
/* Initialize LEDs mounted on STM8L152X-EVAL board */
GPIO_Init(LED_GPIO_PORT, LED_GPIO_PINS, GPIO_Mode_Out_PP_Low_Fast);
GPIO_Init(Button_GPIO_PORT, Button_GPIO_PINS, GPIO_Mode_In_FL_No_IT);
// PD2 TIM1 CH1设置
/* GPIO configuration: TIM1 channel 1 (PD2)*/
GPIO_Init(GPIOD, GPIO_Pin_2 , GPIO_Mode_Out_PP_Low_Fast);
/* Enable TIM1 clock */
CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
//设置TIM1 CH1输出PWM波
/* configure TIM1 channel 1 as PWM Output */
TIM1_OC1Init(TIM1_OCMode_PWM2,
TIM1_OutputState_Enable,
TIM1_OutputNState_Enable,
0x7FF,
TIM1_OCPolarity_Low,
TIM1_OCNPolarity_High,
TIM1_OCIdleState_Set,
TIM1_OCNIdleState_Reset);
/* Set TIM1 Autoreload value*/
TIM1_SetAutoreload(0xFFF);
//2M/4095=488.4HZ
// 使能
/* Enable TIM1 Outputs*/
TIM1_CtrlPWMOutputs(ENABLE);
/* Enable TIM1 */
TIM1_Cmd(ENABLE);
while (1)
{
}
} |
|