直流电机实验
#ifndef DC_MOTOR_H_
#define DC_MOTOR_H_
#include "DSP2833x_Device.h" // DSP2833x 头文件
#include "DSP2833x_Examples.h" // DSP2833x 例子相关头文件
#define DC_MOTOR_INA_SETH (GpioDataRegs.GPASET.bit.GPIO2=1)
#define DC_MOTOR_INA_SETL (GpioDataRegs.GPACLEAR.bit.GPIO2=1)
#define DC_MOTOR_INB_SETH (GpioDataRegs.GPASET.bit.GPIO3=1)
#define DC_MOTOR_INB_SETL (GpioDataRegs.GPACLEAR.bit.GPIO3=1)
#define DC_MOTOR_INC_SETH (GpioDataRegs.GPASET.bit.GPIO4=1)
#define DC_MOTOR_INC_SETL (GpioDataRegs.GPACLEAR.bit.GPIO4=1)
#define DC_MOTOR_IND_SETH (GpioDataRegs.GPASET.bit.GPIO5=1)
#define DC_MOTOR_IND_SETL (GpioDataRegs.GPACLEAR.bit.GPIO5=1)
void DC_Motor_Init(void);
#endif /* DC_MOTOR_H_ */
#include "dc_motor.h"
void DC_Motor_Init(void)
{
EALLOW;
SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;// 开启GPIO时钟
//DC_MOTOR 第1路端口配置
GpioCtrlRegs.GPAMUX1.bit.GPIO2=0;
GpioCtrlRegs.GPADIR.bit.GPIO2=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO3=0;
GpioCtrlRegs.GPADIR.bit.GPIO3=1;
//DC_MOTOR 第2路端口配置
GpioCtrlRegs.GPAMUX1.bit.GPIO4=0;
GpioCtrlRegs.GPADIR.bit.GPIO4=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO5=0;
GpioCtrlRegs.GPADIR.bit.GPIO5=1;
EDIS;
GpioDataRegs.GPACLEAR.bit.GPIO2=1;
GpioDataRegs.GPACLEAR.bit.GPIO3=1;
GpioDataRegs.GPACLEAR.bit.GPIO4=1;
GpioDataRegs.GPACLEAR.bit.GPIO5=1;
}
void main()
{
int i=0;
char key=0;
InitSysCtrl();
LED_Init();
KEY_Init();
DC_Motor_Init();
while(1)
{
key=KEY_Scan(0);
switch(key)
{
case KEY1_PRESS: DC_MOTOR_INA_SETH;DC_MOTOR_INB_SETL;break;
case KEY2_PRESS: DC_MOTOR_INA_SETL;DC_MOTOR_INB_SETH;break;
case KEY3_PRESS: DC_MOTOR_INA_SETL;DC_MOTOR_INB_SETL;break;
}
i++;
if(i%2000==0)
{
LED1_TOGGLE;
}
DELAY_US(100);
}
}