📄 motorhip4081.c
字号:
#define PART_LM3S811
#include "pin_map.h"
#include "motor.h"
#include <hw_ints.h>
#include <hw_sysctl.h>
#include <hw_gpio.h>
#include <interrupt.h>
#include <sysctl.h>
#include "pwm_init.h"
#define SysCtlPeriEnable SysCtlPeripheralEnable
#define SysCtlPeriDisable SysCtlPeripheralDisable
#define GPIOPinTypeIn GPIOPinTypeGPIOInput
#define GPIOPinTypeOut GPIOPinTypeGPIOOutput
//PD3
void Motor1_Enable(tBoolean bEnable)
{
switch(bEnable)
{
case Start:
GPIOPinWrite(Motor1_Enable_PORT,Motor1_Enable_PIN,0x00);
break;
case Stop:
GPIOPinWrite(Motor1_Enable_PORT,Motor1_Enable_PIN,0x04);
break;
}
}
//PD2
void Motor2_Enable(tBoolean bEnable)
{
switch(bEnable)
{
case Start:
GPIOPinWrite(Motor2_Enable_PORT,Motor2_Enable_PIN,0x00);
break;
case Stop:
GPIOPinWrite(Motor2_Enable_PORT,Motor2_Enable_PIN,0x08);
break;
}
}
//PC4
void Motor3_Enable(tBoolean bEnable)
{
switch(bEnable)
{
case Start:
GPIOPinWrite(Motor3_Enable_PORT,Motor3_Enable_PIN,0x00);
break;
case Stop:
GPIOPinWrite(Motor3_Enable_PORT,Motor3_Enable_PIN,0x10);
break;
}
}
void Motor1Direct(tBoolean bDirect)
{
switch(bDirect)
{
case Reverse:
GPIOPinTypePWM(motor1_base, motor1_pwm_reverse);//PE1输出pwm
GPIOPinTypeOut(motor1_base , motor1_pwm_forward);//PE0输出低
GPIOPinWrite(motor1_base , motor1_pwm_forward , 0x00);
break;
case Forward:
GPIOPinTypePWM(motor1_base, motor1_pwm_forward);
GPIOPinTypeOut(motor1_base ,motor1_pwm_reverse);
GPIOPinWrite(motor1_base , motor1_pwm_reverse , 0x00);
break;
}
}
void Motor2Direct(tBoolean bDirect)
{
switch(bDirect)
{
case Reverse:
GPIOPinTypePWM(motor2_base, motor2_pwm_reverse);//PD1输出pwm
GPIOPinTypeOut(motor2_base , motor2_pwm_forward);//PD0输出低
GPIOPinWrite(motor2_base , motor2_pwm_forward , 0x00);
break;
case Forward:
GPIOPinTypePWM(motor2_base, motor2_pwm_forward);
GPIOPinTypeOut(motor2_base ,motor2_pwm_reverse);
GPIOPinWrite(motor2_base , motor2_pwm_reverse , 0x00);
break;
}
}
void Motor3Direct(tBoolean bDirect)
{
switch(bDirect)
{
case Reverse:
GPIOPinTypePWM(motor3_base, motor3_pwm_reverse);//PB1输出pwm
GPIOPinTypeOut(motor3_base , motor3_pwm_forward);//PB0输出低
GPIOPinWrite(motor3_base , motor3_pwm_forward , 0x00);
break;
case Forward:
GPIOPinTypePWM(motor3_base, motor3_pwm_forward);
GPIOPinTypeOut(motor3_base ,motor3_pwm_reverse);
GPIOPinWrite(motor3_base , motor3_pwm_reverse , 0x00);
break;
}
}
void Motor1_Enable_IOinit(void)
{
SysCtlPeriEnable(Motor1_Enable_PERIPH);
GPIOPinTypeOut(Motor1_Enable_PORT, Motor1_Enable_PIN);
}
void Motor2_Enable_IOinit(void)
{
SysCtlPeriEnable(Motor2_Enable_PERIPH);
GPIOPinTypeOut(Motor2_Enable_PORT, Motor2_Enable_PIN);
}
void Motor3_Enable_IOinit(void)
{
SysCtlPeriEnable(Motor3_Enable_PERIPH);
GPIOPinTypeOut(Motor3_Enable_PORT, Motor3_Enable_PIN);
}
void Motor_Int1_A_IOInit(void)
{
SysCtlPeriEnable(Motor_Enco_PERIPH1);
GPIOPinTypeIn(Motor_Enco_PORT1 , Motor1_Enco_A);
GPIOIntTypeSet(Motor_Enco_PORT1 ,
Motor1_Enco_A ,
GPIO_FALLING_EDGE);
IntEnable(Motor1_use_group);
}
void Motor_Int1_B_IOInit(void)
{
SysCtlPeriEnable(Motor_Enco_PERIPH1);
GPIOPinTypeIn(Motor_Enco_PORT1 , Motor1_Enco_B);
GPIOIntTypeSet(Motor_Enco_PORT1 ,
Motor1_Enco_B ,
GPIO_FALLING_EDGE);
IntEnable(Motor1_use_group);
}
void Motor_Int2_A_IOInit(void)
{
SysCtlPeriEnable(Motor_Enco_PERIPH2);
GPIOPinTypeIn(Motor_Enco_PORT2 , Motor2_Enco_A);
GPIOIntTypeSet(Motor_Enco_PORT2 ,
Motor2_Enco_A ,
GPIO_FALLING_EDGE);
IntEnable(Motor2_use_group);
}
void Motor_Int2_B_IOInit(void)
{
SysCtlPeriEnable(Motor_Enco_PERIPH2);
GPIOPinTypeIn(Motor_Enco_PORT2 , Motor2_Enco_B);
GPIOIntTypeSet(Motor_Enco_PORT2 ,
Motor2_Enco_B ,
GPIO_FALLING_EDGE);
IntEnable(Motor2_use_group);
}
void Motor_Int3_A_IOInit(void)
{
SysCtlPeriEnable(Motor_Enco_PERIPH3);
GPIOPinTypeIn(Motor_Enco_PORT3 , Motor3_Enco_A);
GPIOIntTypeSet(Motor_Enco_PORT3 ,
Motor3_Enco_A ,
GPIO_FALLING_EDGE);
IntEnable(Motor3_use_group);
}
void Motor_Int3_B_IOInit(void)
{
SysCtlPeriEnable(Motor_Enco_PERIPH3);
GPIOPinTypeIn(Motor_Enco_PORT3 , Motor3_Enco_B);
GPIOIntTypeSet(Motor_Enco_PORT3 ,
Motor3_Enco_B ,
GPIO_FALLING_EDGE);
IntEnable(Motor3_use_group);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -