You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.6 KiB
77 lines
1.6 KiB
#include "motor.h" |
|
#include "timer.h" |
|
#include "delay.h" |
|
|
|
u16 Ypwmva=0; |
|
u16 Zpwmva=0; |
|
|
|
void motor_Init(void) |
|
{ |
|
|
|
GPIO_InitTypeDef GPIO_InitStructure; |
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA, ENABLE); |
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_0; //PB5、PB0 端口配置 |
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 |
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz |
|
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化 |
|
GPIO_SetBits(GPIOB,GPIO_Pin_5|GPIO_Pin_0); |
|
|
|
|
|
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_0; |
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //PA8,9,10,13,14,15设置成输入,默认下拉 |
|
// GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA |
|
// |
|
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11; |
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //PC10,11设置成输入,默认下拉 |
|
// GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化GPIOC |
|
|
|
} |
|
|
|
void PWM_init(void) |
|
{ |
|
TIM_SetCompare2(TIM3,10); |
|
TIM_SetCompare3(TIM3,10); |
|
} |
|
|
|
void run(void)//前进 |
|
{ |
|
Ypwmva=450; |
|
Zpwmva=450; |
|
Right_moto_go; |
|
Left_moto_go; |
|
} |
|
void stop(void)//停止 |
|
{ |
|
Ypwmva=0; |
|
Zpwmva=0; |
|
Right_moto_go; |
|
Left_moto_go; |
|
} |
|
|
|
void backrun(void)//后退 |
|
{ |
|
Ypwmva=450; |
|
Zpwmva=450; |
|
Left_moto_back; |
|
Right_moto_back; |
|
} |
|
|
|
void leftrun(void)//左转 |
|
{ |
|
Ypwmva=500; |
|
Zpwmva=500; |
|
Right_moto_back; |
|
Left_moto_go; |
|
} |
|
|
|
void rightrun(void)//右转 |
|
{ |
|
Ypwmva=500; |
|
Zpwmva=500; |
|
Right_moto_go; |
|
Left_moto_back; |
|
|
|
} |
|
|
|
|
|
|