|
#include "motor.h"
#include "interface.h"
#include "stm32f10x.h"
#include "delay.h"
//GPIOéèÖÃ
void MotorGPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_7| GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7| GPIO_Pin_6|GPIO_Pin_8| GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
//ÏòÇ°
void CarGo(void)
{
TIM_SetCompare1(TIM3 , 430);
TIM_SetCompare2(TIM3 , 430);
TIM_SetCompare3(TIM3 , 430);
TIM_SetCompare4(TIM3 , 430);
FRONT_LEFT_F = 1;
FRONT_LEFT_B = 0;
BEHIND_LEFT_F =1;
BEHIND_LEFT_B = 0;
FRONT_RIGHT_F = 1;
FRONT_RIGHT_B = 0;
BEHIND_RIGHT_F = 0;
BEHIND_RIGHT_B = 1;
delay_ms(100);
}
//Ïòoó
void CarBack(void)
{
TIM_SetCompare1(TIM3 , 400);
TIM_SetCompare2(TIM3 , 400);
TIM_SetCompare3(TIM3 , 400);
TIM_SetCompare4(TIM3 , 400);
FRONT_LEFT_F = 0;
FRONT_LEFT_B = 1;
BEHIND_LEFT_F = 0;
BEHIND_LEFT_B = 1;
FRONT_RIGHT_F = 0;
FRONT_RIGHT_B = 1;
BEHIND_RIGHT_F = 1;
BEHIND_RIGHT_B = 0;
delay_ms(100);
}
//Ïòóò
void CarLeft(void)
{
TIM_SetCompare1(TIM3 , 300);
TIM_SetCompare2(TIM3 , 300);
TIM_SetCompare4(TIM3 , 350);
TIM_SetCompare3(TIM3 ,350);
FRONT_LEFT_F = 1;
FRONT_LEFT_B = 0;
BEHIND_LEFT_F = 1;
BEHIND_LEFT_B = 0;
FRONT_RIGHT_F = 0;
FRONT_RIGHT_B = 1;
BEHIND_RIGHT_F = 1;
BEHIND_RIGHT_B = 0;
delay_ms(100);
}
//′óóò
void CarBigLeft(void)
{
TIM_SetCompare1(TIM3 , 400);
TIM_SetCompare2(TIM3 , 400);
FRONT_LEFT_F = 1;
FRONT_LEFT_B = 0;
BEHIND_LEFT_F = 1;
BEHIND_LEFT_B = 0;
FRONT_RIGHT_F = 0;
FRONT_RIGHT_B = 0;
BEHIND_RIGHT_F = 0;
BEHIND_RIGHT_B = 0;
delay_ms(100);
}
//Ïò×ó
void CarRight(void)
{
TIM_SetCompare1(TIM3 , 350);
TIM_SetCompare2(TIM3 , 350);
TIM_SetCompare4(TIM3 , 300);
TIM_SetCompare3(TIM3 ,300);
FRONT_LEFT_F = 0;
FRONT_LEFT_B = 1;
BEHIND_LEFT_F = 0;
BEHIND_LEFT_B = 1;
FRONT_RIGHT_F = 1;
FRONT_RIGHT_B = 0;
BEHIND_RIGHT_F = 0;
BEHIND_RIGHT_B = 1;
}
//′ó×ó
void CarBigRight(void)
{
TIM_SetCompare4(TIM3 , 400);
TIM_SetCompare3(TIM3 , 400);
FRONT_LEFT_F = 0;
FRONT_LEFT_B = 0;
BEHIND_LEFT_F = 0;
BEHIND_LEFT_B = 0;
FRONT_RIGHT_F = 1;
FRONT_RIGHT_B = 0;
BEHIND_RIGHT_F = 1;
BEHIND_RIGHT_B = 0;
}
//í£Ö1
void CarStop(void)
{
TIM_SetCompare1(TIM3 , 900);
TIM_SetCompare2(TIM3 , 900);
TIM_SetCompare3(TIM3 , 900);
TIM_SetCompare4(TIM3 , 900);
}
void MotorInit(void)
{
MotorGPIO_Configuration();
CarStop();
}
|
-
-
循迹小车.rar
278.84 KB, 下载次数: 156, 下载积分: 黑币 -5
评分
-
查看全部评分
|