七路PWM波
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "usart.h"
- #include "timer.h"
-
- int main(void)
- {
- // u16 led0pwmval=0;
- // u8 dir=1;
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- LED_Init(); //LED端口初始化
- TIM3_PWM_Init(899,0); //不分频。PWM频率=72000000/900=80Khz
- TIM2_PWM_Init(899,0);
- while(1)
- {
- delay_ms(10);
- // if(dir)led0pwmval++;
- // else led0pwmval--;
- // if(led0pwmval>300)dir=0;
- // if(led0pwmval==0)dir=1;
- // TIM_SetCompare2(TIM3,150); //M00 M01
- //TIM_SetCompare1(TIM3,80); //M1
- // TIM_SetCompare3(TIM3,60); //M41
- //TIM_SetCompare4(TIM3,30); //M40
-
- // TIM_SetCompare1(TIM2,80); //
- TIM_SetCompare3(TIM2,60); //M2
- // TIM_SetCompare4(TIM2,30); //M3
- }
- }
复制代码
所有资料51hei提供下载:
机械臂.rar
(286.42 KB, 下载次数: 9)
|