51单片机控制三个步进电机的启动停止加protrus仿真
立即下载
资源介绍:
51单片机控制三个步进电机的启动停止加protrus仿真
#include
#define uchar unsigned char
#define uint unsigned int
#define OUT1 P1
#define OUT2 P2
#define OUT3 P3
sbit key0 = P0^1;
sbit key1 = P0^0;
sbit key2 = P0^2;
sbit key3 = P0^3;
sbit key4 = P0^4;
sbit key5 = P0^5;
//void delay(uint);
uint TIME,TIME1,TIME2;
uchar code turn[] = {0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};
void main()
{
uchar a,b,c;
OUT1 = 0x03;
OUT2 = 0x03;
OUT3 = 0x03;
TMOD = 0x01;
TH0 = 0x3c;
TL0 = 0xb0;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1)
{
if (key0&&key1) TIME=0;
if (!key0)
{
if (TIME==2)
{
a = a<8?a+1:0;
OUT1 = turn[a];
TIME = 0;
}
}
if (!key1)
{
if (TIME==2)
{
a = a>0?a-1:7;
OUT1 = turn[a];
TIME = 0;
}
}
if (key2&&key3) TIME1=0;
if (!key2)
{
if (TIME1==2)
{
b = b<8?b+1:0;
OUT2 = turn[b];
TIME1 = 0;
}
}
if (!key3)
{
if (TIME1==2)
{
b = b>0?b-1:7;
OUT2 = turn[b];
TIME1 = 0;
}
}
if (key4&&key5) TIME2=0;
if (!key4)
{
if (TIME2==2)
{
c = c<8?c+1:0;
OUT3 = turn[c];
TIME2 = 0;
}
}
if (!key5)
{
if (TIME2==2)
{
c = c>0?c-1:7;
OUT3 = turn[c];
TIME2 = 0;
}
}
}
}
void timer()interrupt 1
{
TH0=0x3c;
TL0=0xb0;
TIME++;
TIME1++;
TIME2++;
}