////////////////////////汇诚科技////////////////////
//////////////////http://www.ourhc.cn///////////////
///////////////////步进电机正转调试程序/////////////
#include<reg52.h>
/*****************************************************************/
code unsigned char run[8]={ 0x04,0x06,0x02,0x0a,0x08,0x09,0x01,0x05};
unsigned char a,s,i,j,k;
sbit ANJIAN=P2^0;
sbit chuanganqi=P3^0;
void delay(i)//延时函数
{
for(j=0;j<i;j++)
for(k=0;k<250;k++);
}
main()
{
unsigned char z,y;
y=10; //定义延时时间,时间越长电机转速越慢反之则快
a=0;
while(1)
{
if((ANJIAN==0)||(chuanganqi==0))
{
a++;
while((!ANJIAN)||(!chuanganqi));
//delay(y);
switch(a)
{
case 11=run[0];delay(y)1=run[2];delay(y);break;
case 21=run[4];delay(y)1=run[6];delay(y);break;
case 31=run[0];delay(y)1=run[2];delay(y);break;
case 41=run[4];delay(y)1=run[6];delay(y);break;
case 51=run[0];delay(y)1=run[2];delay(y);break;
case 61=run[4];delay(y)1=run[6];delay(y);break;
case 71=run[4];delay(y)1=run[2];delay(y);break;
case 81=run[0];delay(y)1=run[6];delay(y);break;
case 91=run[4];delay(y)1=run[2];delay(y);break;
case 101=run[0];delay(y)1=run[6];delay(y);break;
case 11:P1=run[4];delay(y);P1=run[2];delay(y);break;
case 12:P1=run[0];delay(y);P1=run[6];delay(y);break;
//case 13:P1=run[0];delay(y);P1=run[1];delay(y);break;
case 13:a=0;break;
default:break;
}
}
}
}
|