可以控制两个舵机,IO口如果要改的话只要改宏定义就可以了,改的话别忘记改时钟
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "pwm.h"
int main(void)
{
u16 led0pwmval=0;
//u8 dir=1;
delay_init(); //延时函数初始化
LED_Init(); //初始化与LED连接的硬件接口
TIM1_PWM_Init(1439,999);//不分频。PWM频率=72000/(899+1)=80Khz
while(1)
{
// led0pwmval=37;
// TIM_SetCompare1(TIM1,led0pwmval);
// TIM_SetCompare2(TIM1,led0pwmval);
// delay_ms(1000); //0度,延时1s
//
// led0pwmval=60;//45度
// TIM_SetCompare1(TIM1,60); //左右
// TIM_SetCompare2(TIM1,50); //上下
// delay_ms(1000);
//
//
// led0pwmval=93; //90度
// TIM_SetCompare1(TIM1,93);
// TIM_SetCompare2(TIM1,100);
// delay_ms(1000);
// led0pwmval=125; //135度
// TIM_SetCompare1(TIM1,led0pwmval);
// TIM_SetCompare2(TIM1,led0pwmval);
// delay_ms(1000);
//
led0pwmval=160;
TIM_SetCompare1(TIM1,led0pwmval);
TIM_SetCompare2(TIM1,led0pwmval);
delay_ms(1000); //180度
}
}
全部资料51hei下载地址:
舵机程序.7z
(184.78 KB, 下载次数: 192)
|