今天这个步进电机的切换完全实现了,没错,,就是在for循环中加上while(k1==0||k2==0)break;;
加上break就能够实现了,感谢各位对我的帮组尤其是感谢12 楼何13 楼:victory:下面是运行成功后的代码,,嘿嘿#include <reg51.h>
typedef unsigned char uint8;
code uint8 a[]={0xfe,0xfc,0xfd,0xf9,0xfb,0xf3,0xf7,0xf6};//反转
code uint8 b[]={0xf6,0xf7,0xf3,0xfb,0xf9,0xfd,0xfc,0xfe};//正转
sbit K1=P2^0;
sbit K2=P2^1;
sbit K3=P2^2;
uint8 i=0;
void delay(unsigned int t)
{
unsigned int k;
while(t--)
{
for(k=0; k<80; k++)
{ }
}
}
void timer1_init()
{
TMOD=0x10;
TH1=0xb1;
TL1=0xe0;
TR1=1;
ET1=1;
EA=1;
}
void main()
{
timer1_init();
if(K1==0)
{
while(1);
}
if(K2==0)
{
while(1);
}
if(K3==0)
{
while(1);
}
}
void inte() interrupt 3
{
TH1=0xb1;
TL1=0xe0;
TR1=1;
if(K1==0)
{
for(i=0;i<8;i++)
{
P1=a[i];
if(i==7)
{
i=0;
}
delay(10);
if(K2==0||K3==0)
break;
}
while(K1==0);
}
if(K2==0)
{
for(i=0;i<8;i++)
{
P1=b[i];
if(i==7)
{
i=0;
}
delay(10);
if(K1==0||K3==0)
{
break;
}
}
while(K2==0);
}
if(K3==0)
{
for(i=0;i<8;i++)
{
P1=0XFF;
delay(10);
if(K1==0||K3==0)
break;
}
while(K3==0);
}
}
|