我想:发送1步进电机正转0停止。(其他功能可以不看)
现在:发送1步进电机正转在发1停止。
#include <REG52.H>
#define uint unsigned int
#define uchar unsigned char
uchar state=0;
uchar both=0;
uint t;
uchar count= 0;
unsigned char receiveData='0';
sbit k1=P3^7;
sbit pul1=P1^0;
sbit dir1=P1^1;
sbit en1=P1^2;
sbit pul2=P2^0;
sbit dir2=P2^1;
sbit en2=P2^2;
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
key0()interrupt 0
{
IE0=1;
TF0=0;
IE1=0;
{pul1=0;
delay(1);
pul1=0;
delay(1);
}
}
key1()interrupt 1
{
count++;
if(count==1)count=0;
{
TF0=1;
IE1=0;
{
dir1=0;
pul1=1;
delay(1);
pul1=0;
delay(1);
}
}
}
key2()interrupt 2
{
IE1=1;
{
for(t=0;t<400;t++)
{
dir2=1;
pul2=1;
delay(1);
pul2=0;
delay(1);
}
delay(500);
for(t=0;t<400;t++)
{
dir2=0;
pul2=1;
delay(1);
pul2=0;
delay(1);
}
}
IE1=0;
}
void motor1_zz()
{
dir1=1;
pul1=1;
delay(1);
pul1=0;
delay(1);
}
void main()
{
SCON=0X50;
TMOD=0x26;
PCON=0X80;
TH1=0XFA;
TL1=0XFA;
//ES=1;
//EA=1;
TR1=1;
IP=0x10;
IT0=1;
IT1=1;
TH0=TL0=0xff;
ET0=1;
TR0=1;
TF0=0;
IE=0X97;
while(1)
{
while(both==0)
{
if(receiveData=='1')
{
state=1;
receiveData='0';
break;
}
P1=0x0f;
}
while(state==1)
{
if(receiveData=='1')
{
state=1;
receiveData='0';
break;
}
motor1_zz();
}
}}
void Usart() interrupt 4
{
IE0=0;
receiveData=SBUF
while(!RI);
RI = 0;
}
|