单片机控制环形分配
1个回答
展开全部
#include<reg51.h>
#define uchar unsigned char
uchar stepd[]={0x01,0x03,0x02,0x06,0x04,0xc0,0x08,0x09};
//uchar step[]={0x01,0x02,0x04,0x08};
uchar num=0,fx=0;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
void t0isr() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
P2=stepd[num];
if(fx==0){num++;num%=8;}
if(fx==1)
{
if(num==0)num=7;
else num--;
}
}
main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(key1==0)
{
while(key1==0);
TR0=~TR0;
}
if(key2==0)
{
while(key2==0);
fx=0;
}
if(key3==0)
{
while(key3==0);
fx=1;
}
}
}
#define uchar unsigned char
uchar stepd[]={0x01,0x03,0x02,0x06,0x04,0xc0,0x08,0x09};
//uchar step[]={0x01,0x02,0x04,0x08};
uchar num=0,fx=0;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
void t0isr() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
P2=stepd[num];
if(fx==0){num++;num%=8;}
if(fx==1)
{
if(num==0)num=7;
else num--;
}
}
main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(key1==0)
{
while(key1==0);
TR0=~TR0;
}
if(key2==0)
{
while(key2==0);
fx=0;
}
if(key3==0)
{
while(key3==0);
fx=1;
}
}
}
追问
能不能简单的解释一下,就这样真心看不懂啊,谢谢!
追答
#include
#define uchar unsigned char
uchar stepd[]={0x01,0x03,0x02,0x06,0x04,0xc0,0x08,0x09};//相序分配关系
//uchar step[]={0x01,0x02,0x04,0x08};
uchar num=0,fx=0;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
void t0isr() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
P2=stepd[num]; //驱动电机
if(fx==0){num++;num%=8;} //正向转动
if(fx==1) //反向转动
{
if(num==0)num=7;
else num--;
}
}
main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(key1==0) //按该键启停切换
{
while(key1==0);
TR0=~TR0;
}
if(key2==0) //该键正向
{
while(key2==0);
fx=0;
}
if(key3==0) //该键反向
{
while(key3==0);
fx=1;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询