基于单片机的步进电机控制系统设计

# include & ltreg 51 . h & gt;

#定义uchar无符号字符

uchar stepd[]={0x01,0x03,0x02,0x06,0x04,0xc0,0x08,0x 09 };

uchar num=0,FX = 0;

sbit key1=p3^0;

sbit key2=p3^1;

sbit key3=p3^2;

void t0isr()中断1

{

TH0 =(65536-10000)/256;

TL0 =(65536-10000)% 256;

P2 = stepd[数字];

if(FX = = 0){ num++;num % = 8;}

if(fx==1)

{

if(num = = 0)num = 7;

else num-;

}

}

主()

{

TMOD = 0x 01;

TH0 =(65536-10000)/256;

TL0 =(65536-10000)% 256;

TR0 = 1;

ET0 = 1;

EA = 1;

while(1)

{

if(key1==0)

{

while(key 1 = = 0);

TR0 = ~ TR0

}

if(key2==0)

{

while(key 2 = = 0);

FX = 0;

}

if(key3==0)

{

while(key 3 = = 0);

FX = 1;

}

}

}