|
- //#include "led.h"
- #include "delay.h"
- //#include "key.h"
- //#include "sys.h"//<timer.h>里包含过了
- //#include "usart.h"
- #include "timer.h"
-
- int main(void)
- {
- u8 i;
- u16 pwmval=0;
-
- delay_init(); //延时函数初始化
- // TIM3_PWM_Init(1999,719); //不分频。PWM频率=100000/2000=50hz
- TIM4_PWM_Init(1999,719); //不分频。PWM频率=100000/2000=50hz
- while(1)
- {
- delay_ms(500);
- pwmval=1750; //对应180度
- TIM_SetCompare2(TIM3,pwmval);
- delay_ms(500);
- pwmval=1800; //对应135度
- TIM_SetCompare2(TIM3,pwmval);
-
- delay_ms(500);
- pwmval=1850; //对应90度
- TIM_SetCompare2(TIM3,pwmval);
- delay_ms(500);
- pwmval=1900; //对应45度
- TIM_SetCompare2(TIM3,pwmval);
- delay_ms(500);
- pwmval=1950; //对应0度
- TIM_SetCompare2(TIM3,pwmval);
- #if 0
- pwmval=1950;
- for(i=0;i<5;i++)//依次从0度转到180度每隔45度转一次
- {
- delay_ms(1000);
- //TIM_SetCompare2(TIM3,pwmval);
- TIM_SetCompare1(TIM4,pwmval);
- pwmval-=50;
- }
- #endif
- }
- }
复制代码
|
-
-
mg90s.7z
185.64 KB, 下载次数: 27, 下载积分: 黑币 -5
评分
-
查看全部评分
|