/*这六个IO口用来换相*/
#define XA1_DIR GpioMuxRegs.GPBDIR.bit.GPIOB13 //B13 B14 A相
#define XA2_DIR GpioMuxRegs.GPBDIR.bit.GPIOB14
#define XB1_DIR GpioMuxRegs.GPBDIR.bit.GPIOB2 //B2 B3 B相
#define XB2_DIR GpioMuxRegs.GPBDIR.bit.GPIOB3
#define XC1_DIR GpioMuxRegs.GPBDIR.bit.GPIOB4 //B4 B5 C相
#define XC2_DIR GpioMuxRegs.GPBDIR.bit.GPIOB5
#define PWM8_DIR GpioMuxRegs.GPBDIR.bit.GPIOB1//指示灯
#define XA1_ON GpioDataRegs.GPBSET.bit.GPIOB13=1
#define XA1_OFF GpioDataRegs.GPBCLEAR.bit.GPIOB13=1
#define XA2_ON GpioDataRegs.GPBSET.bit.GPIOB14=1
#define XA2_OFF GpioDataRegs.GPBCLEAR.bit.GPIOB14=1
#define XB1_ON GpioDataRegs.GPBSET.bit.GPIOB2=1
#define XB1_OFF GpioDataRegs.GPBCLEAR.bit.GPIOB2=1
#define XB2_ON GpioDataRegs.GPBSET.bit.GPIOB3=1
#define XB2_OFF GpioDataRegs.GPBCLEAR.bit.GPIOB3=1
#define XC1_ON GpioDataRegs.GPBSET.bit.GPIOB4=1
#define XC1_OFF GpioDataRegs.GPBCLEAR.bit.GPIOB4=1
#define XC2_ON GpioDataRegs.GPBSET.bit.GPIOB5=1
#define XC2_OFF GpioDataRegs.GPBCLEAR.bit.GPIOB5=1
#define PWM8_ON GpioDataRegs.GPBSET.bit.GPIOB1=1 /*指示灯*/
#define PWM8_OFFGpioDataRegs.GPBCLEAR.bit.GPIOB1=1
/*****************************换相程序****************************************/
void huanxiang(void)//没写反转
{
while(1)
{
if(PA1_DAT==1&&PB1_DAT==0&&PC1_DAT==0)//开A相
XA1_OFF;
XA2_OFF;
XB1_ON;
XB2_ON;
XC1_ON;
XC2_ON;
if(PA1_DAT==1&&PB1_DAT==1&&PC1_DAT==0)//开AB相
XA1_OFF;
XA2_OFF;
XB1_OFF;
XB2_OFF;
XC1_ON;
XC2_ON;
if(PA1_DAT==0&&PB1_DAT==1&&PC1_DAT==0)//开B相
XA1_ON;
XA2_ON;
XB1_OFF;
XB2_OFF;
XC1_ON;
XC2_ON;
if(PA1_DAT==0&&PB1_DAT==1&&PC1_DAT==1)//开BC相
XA1_ON;
XA2_ON;
XB1_OFF;
XB2_OFF;
XC1_OFF;
XC2_OFF;
if(PA1_DAT==0&&PB1_DAT==0&&PC1_DAT==1)//开C相
XA1_ON;
XA2_ON;
XB1_ON;
XB2_ON;
XC1_OFF;
XC2_OFF;
if(PA1_DAT==1&&PB1_DAT==0&&PC1_DAT==1)//开CA相
XA1_OFF;
XA2_OFF;
XB1_ON;
XB2_ON;
XC1_OFF;
XC2_OFF;
}
}
我想问一下 我这样写行不 我不太会 换向 三相的开关磁阻电机 |