|

楼主 |
发表于 2024-4-4 11:42:26
|
显示全部楼层
void motor_init(void)
{
GPIO_InitTypeDef MOTOR_Structure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //系统时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //系统时钟
MOTOR_Structure.GPIO_Pin = IN1_pin;
MOTOR_Structure.GPIO_Speed = GPIO_Speed_10MHz ;
MOTOR_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(IN1_port, &MOTOR_Structure);
MOTOR_Structure.GPIO_Pin = IN2_pin;
MOTOR_Structure.GPIO_Speed = GPIO_Speed_10MHz ;
MOTOR_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(IN2_port, &MOTOR_Structure);
MOTOR_Structure.GPIO_Pin = IN3_pin;
MOTOR_Structure.GPIO_Speed = GPIO_Speed_10MHz ;
MOTOR_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(IN3_port, &MOTOR_Structure);
MOTOR_Structure.GPIO_Pin = IN4_pin;
MOTOR_Structure.GPIO_Speed = GPIO_Speed_10MHz ;
MOTOR_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(IN4_port, &MOTOR_Structure);
GPIO_ResetBits(IN1_port, IN1_pin);
GPIO_ResetBits(IN2_port, IN2_pin);
GPIO_ResetBits(IN3_port, IN3_pin);
GPIO_ResetBits(IN4_port, IN4_pin);
}
void left_motor_forward(void)
{
GPIO_ResetBits(IN1_port, IN1_pin);
GPIO_SetBits(IN2_port, IN2_pin);
}
void left_motor_back(void)
{
GPIO_SetBits(IN1_port, IN1_pin);
GPIO_ResetBits(IN2_port, IN2_pin);
}
void right_motor_forward(void)
{
GPIO_SetBits(IN3_port, IN3_pin);
GPIO_ResetBits(IN4_port, IN4_pin);
}
void right_motor_back(void)
{
GPIO_ResetBits(IN3_port, IN3_pin);
GPIO_SetBits(IN4_port, IN4_pin);
}
void left_motor_stop(void)
{
GPIO_ResetBits(IN1_port, IN1_pin);
GPIO_ResetBits(IN2_port, IN2_pin);
}
void right_motor_stop(void)
{
GPIO_ResetBits(IN3_port, IN3_pin);
GPIO_ResetBits(IN4_port, IN4_pin);
}
详细解释该代码 |
|