步进电机实验
#include "step_motor.h"void Step_Motor_Init(void)
{EALLOW;SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;// 开启GPIO时钟//Step_MOTOR端口配置GpioCtrlRegs.GPAMUX1.bit.GPIO2=0;GpioCtrlRegs.GPADIR.bit.GPIO2=1;GpioCtrlRegs.GPAMUX1.bit.GPIO3=0;GpioCtrlRegs.GPADIR.bit.GPIO3=1;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;
}
#ifndef STEP_MOTOR_H_
#define STEP_MOTOR_H_#include "DSP2833x_Device.h" // DSP2833x 头文件
#include "DSP2833x_Examples.h" // DSP2833x 例子相关头文件#define STEP_MOTOR_4LINE2
//#define STEP_MOTOR_5LINE4#define MOTO_OUTA_SETH (GpioDataRegs.GPASET.bit.GPIO2=1)
#define MOTO_OUTA_SETL (GpioDataRegs.GPACLEAR.bit.GPIO2=1)#define MOTO_OUTB_SETH (GpioDataRegs.GPASET.bit.GPIO3=1)
#define MOTO_OUTB_SETL (GpioDataRegs.GPACLEAR.bit.GPIO3=1)#define MOTO_OUTC_SETH (GpioDataRegs.GPASET.bit.GPIO4=1)
#define MOTO_OUTC_SETL (GpioDataRegs.GPACLEAR.bit.GPIO4=1)#define MOTO_OUTD_SETH (GpioDataRegs.GPASET.bit.GPIO5=1)
#define MOTO_OUTD_SETL (GpioDataRegs.GPACLEAR.bit.GPIO5=1)void Step_Motor_Init(void);#endif /* STEP_MOTOR_H_ */
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File#include "leds.h"
#include "key.h"
#include "step_motor.h"#ifdef STEP_MOTOR_5LINE4
unsigned char Step_table_ZTurn[]={0xfff7,0xfffb,0xffdf,0xffef};
unsigned char Step_table_FTurn[]={0xffef,0xffdf,0xfffb,0xfff7};
#endif#ifdef STEP_MOTOR_4LINE2
unsigned char Step_table_ZTurn[]={0xfff7,0xffdf,0xfffb,0xffef};
unsigned char Step_table_FTurn[]={0xffef,0xfffb,0xffdf,0xfff7};
#endif/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{int i=0;char key=0;short cnt=0;char j=0;InitSysCtrl();LED_Init();KEY_Init();Step_Motor_Init();while(1){key=KEY_Scan(0);#ifdef STEP_MOTOR_4LINE2if(key==KEY1_PRESS){cnt=1024;while(cnt--){for(j=0;j<4;j++){GpioDataRegs.GPADAT.all=Step_table_ZTurn[j];DELAY_US(5000);}}}else if(key==KEY2_PRESS){cnt=1024;while(cnt--){for(j=0;j<4;j++){GpioDataRegs.GPADAT.all=Step_table_FTurn[j];DELAY_US(5000);}}}
#endif#ifdef STEP_MOTOR_5LINE4if(key==KEY1_PRESS){cnt=1024;while(cnt--){for(j=0;j<4;j++){GpioDataRegs.GPADAT.all=Step_table_ZTurn[j];DELAY_US(5000);}}}else if(key==KEY2_PRESS){cnt=1024;while(cnt--){for(j=0;j<4;j++){GpioDataRegs.GPADAT.all=Step_table_FTurn[j];DELAY_US(5000);}}}
#endifi++;if(i%2000==0){LED1_TOGGLE;}DELAY_US(100);}
}