这是我的程序,运动后不停止,请大神们指点一下
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar runz[]={0x08,0x0a,0x02,0x06,0x04,0x05,0x01,0x09}; //两相四线八拍工作方式正转
uchar runf[]={0x09,0x01,0x05,0x04,0x06,0x02,0x0a,0x08}; //两相四线八拍工作方式反转
uchar sc;
int a,b1,b2,b3,c,d1,d2,d3,m1,m2,m3,wy,j,k,i,n1,n2,n3,x,y,z,e,step,c0;
char str[10],str1[2],str2[2],str3[2],str4[2];
void timerA_init(); //定时器A初始化
void InitUSART();
void out();
void xout();
void yout();
void zout();
void main ()
{
WDTCTL = WDTPW + WDTHOLD;//停止看门狗
P2DIR=0Xff; //控制输出
P2SEL=0x00; //关闭P2口第二功能
P2OUT=0Xff;//P2先赋一个ff初值
P3DIR=0xff;
P3SEL=0x00;
P3OUT=0Xff;
P5DIR=0xff;
P5SEL=0x00;
P5OUT=0Xff;
a=200;b1=0;b2=0;b3=0;d1=0;d2=0;d3=0;m1=0;m2=0;m3=0;c=0;wy=0;j=0;k=0;i=0;n1=0;n2=0;n3=0;x=0;y=0;z=0;step=1;c0=0;
InitUSART();
timerA_init();
while(1)
{
if(c==1)
{
if(step==1)
{
if(m1 {e=2;}
else if(m1>d1)
{e=3;}
else
{
e=0;
m1=d1;
step=2;
}
}
if(step==2)
{
if(m2 {e=4;}
else if(m2>d2)
{e=5;}
else
{
e=0;
m2=d2;
step=3;
}
}
if(step==3)
{
if(m3 {e=6;}
else if(m3>d3)
{e=7;}
else
{
e=0;
m3=d3;
step=1;
c=0;
}
}
}
else
{e=c;}
}
}
void out()
{
switch(e)
{
case 0:
P2OUT=0x01;
P3OUT=0x01;
P5OUT=0x01;
break;
case 1:
P2OUT=0x01;
P3OUT=0x01;
P5OUT=0x01;
break;
case 2:
P2OUT=runz[wy];m1++;
P3OUT=0x01;
P5OUT=0x01;
break;
case 3:
P2OUT=runf[wy];m1--;
P3OUT=0x01;
P5OUT=0x01;
break;
case 4:
P3OUT=runz[wy];m2++;
P2OUT=0x01;
P5OUT=0x01;
break;
case 5:
P3OUT=runf[wy];m2--;
P2OUT=0x01;
P5OUT=0x01;
break;
case 6:
P5OUT=runz[wy];m3++;
P2OUT=0x01;
P3OUT=0x01;
break;
case 7:
P5OUT=runf[wy];m3--;
P2OUT=0x01;
P3OUT=0x01;
break;
default:break;
}
}
void timerA_init() //定时器A初始化
{
TACTL=TASSEL_1+MC_1; //定时器A时钟源为ACLK,增计数模式
CCTL0 = CCIE; //CCR0中断允许
CCR0=a;//定时溢出值
_EINT(); //开总中断使能
}
#pragma vector = TIMERA0_VECTOR //中断服务子程序
__interrupt void timerA()
{
out();
wy++;
if(wy==8)
{
wy=0;
}
}
void InitUSART(void)
{
U1CTL |= CHAR; // 8bit字符
U1TCTL |= SSEL0; // ACLK
U1BR1 = 0x00; // 4800波特率
U1BR0 = 0x06;
U1MCTL = 0x6f;
U1CTL &= ~SWRST; // 设置完成
ME2 |= UTXE1 + URXE1; // 使能TXD和RXD
IE2 |= URXIE1; // 接收中断
P4SEL |= BIT0+BIT1; // 引脚切换到特殊功能上
_BIS_SR(GIE); // 使能总中断
}
#pragma vector=USART1RX_VECTOR
__interrupt void Usart1Rx()
{
while (!(IFG1 & UTXIFG0));
str[j++]=U1RXBUF;
if(str[j]==NULL)
{
for(k=0,i=0,c0=0;k<2;)
{
str1[k]=(char)str[i];
if(str1[k]>='0'&&str1[k]<='9')
{
c0=c0*10+str1[k]-'0';
}
k++;i++;
if(k==2)
{c=c0;}
}
for(n1=0,i=2,b1=0;n1<2;)
{
str2[n1]=(char)str[i];
if(str2[n1]>='0'&&str2[n1]<='9')
{
b1=b1*10+str2[n1]-'0';
}
n1++;i++;
if(n1==2)
{d1=b1*200;}
}
for(n2=0,i=4,b2=0;n2<2;)
{
str3[n2]=(char)str[i];
if(str3[n2]>='0'&&str3[n2]<='9')
{
b2=b2*10+str3[n2]-'0';
}
n2++;i++;
if(n2==2)
{d2=b2*200;}
}
for(n3=0,i=6,b3=0;n3<2;)
{
str4[n3]=(char)str[i];
if(str4[n3]>='0'&&str4[n3]<='9')
{
b3=b3*10+str4[n3]-'0';
}
n3++;i++;
if(n3==2)
{d3=b3*200;}
}
j=0;
i=0;
IE2 |= UTXIE1;
U1TXBUF=str[i++];
}
}
#pragma vector=USART1TX_VECTOR
__interrupt void Usart1Tx()
{
while (!(IFG1 & UTXIFG0));
U1TXBUF=str[i++];
if(str[i]==NULL)
{
IE2&= ~UTXIE1;
}
} |