求大神啊,求哪位兄弟帮忙解释一下下面这段程序 是做六自由度机械手的 #include <stdio.h>
#include <REG52.h>
#define uchar unsigned char
#define uint unsigned int
sbit Out1=P2^0;
sbit Out2=P2^1;
sbit Out3=P2^2;
sbit Out4=P2^3;
sbit Out5=P2^4;
sbit Out6=P2^5;
void PWM(uint a, uint b,uint c, uint d,uint e,uint f) ;
void delay_nms(unsigned int n)
{uint x ,y ;
for(x=100;x>0;x--)
for(y=n;y>0;y--);
}
void PWM(uint a, uint b,uint c, uint d,uint e,uint f)
{
{uchar A,B,C,D,E,F;
uint M=500;
A=250-a;
B=250-b;
C=250-c;
D=250-d;
E=250-e;
F=250-f;
do { Out1 = 1; } while(a--);
do { Out1 = 0; } while(A--);
do { Out2 = 1; } while(b--);
do { Out2 = 0; } while(B--);
do { Out3 = 1; } while(c--);
do { Out3 = 0; } while(C--);
do { Out4 = 1; } while(d--);
do { Out4 = 0; } while(D--);
do { Out5 = 1; } while(e--);
do { Out5 = 0; } while(E--);
do { Out6 = 1; } while(f--);
do { Out6 = 0; } while(F--);
do{ }while(M--);
}
}
main()
{
while(1)
{
SCON = 0x50; //REN=1允许串行接受状态,串口工作模式1
TMOD = 0x20; //定时器工作方式2
PCON = 0x80;
//TH1 = 0xFD; //baud*2 /* reload value 19200、数据位8、停止位1。效验位无 (11.0592)
TH1 = 0xF3; // //baud*2 /* 波特率4800、数据位8、停止位1。效验位无 (12M)
TL1 = 0xF3;
TR1 = 1;
ES = 1; //开串口中断
EA = 1; // 开总中断
while(1)
{
if(RI)
{
RI=0;
m=SBUF-48;
if(m==1)
{
if(a<=120) a=a+3;
else a=a+1;
}
if(m==2)
{
if(a>=180)a=a-3;
else a=a-1;
}
if(m==3) b=b+1;
if(m==4) b=b-1;
if(m==5) c=c+1;
if(m==6) c=c-1;
if(m==7) d=d+1;
if(m==8) d=d-1;
if(m==9) e=e+1;
if(m==0) e=e-1;
if(a<=69) a=69;
if(a>=229) a=228;
if(b<=69) b=69;
if(b>=229) b=228;
if(c<=69) b=69;
if(c>=229) b=228;
if(d<=69) b=69;
if(d>=229) b=228;
if(e<=69) b=69;
if(e>=229) b=228;
}
else
{
PWM(100,130,120,130,140,110);
delay_nms(1000);
PWM(130,150,130,150,150,130);
delay_nms(1000);
PWM(140,170,150,160,170,160);
delay_nms(1000);
PWM(160,175,170,180,180,180);
delay_nms(1000);
PWM(200,180,190,180,190,190);
delay_nms(1000);
PWM(160,175,170,180,180,180);
delay_nms(1000);
PWM(140,170,150,160,170,160);
delay_nms(1000);
PWM(130,150,130,150,150,130);
delay_nms(1000);
PWM(100,130,120,130,140,110);
delay_nms(1000);
}
}
}
#include <REG52.h>
#define uchar unsigned char
#define uint unsigned int
sbit Out1=P2^0;
sbit Out2=P2^1;
sbit Out3=P2^2;
sbit Out4=P2^3;
sbit Out5=P2^4;
sbit Out6=P2^5;
void PWM(uint a, uint b,uint c, uint d,uint e,uint f) ;
void delay_nms(unsigned int n)
{uint x ,y ;
for(x=100;x>0;x--)
for(y=n;y>0;y--);
}
void PWM(uint a, uint b,uint c, uint d,uint e,uint f)
{
{uchar A,B,C,D,E,F;
uint M=500;
A=250-a;
B=250-b;
C=250-c;
D=250-d;
E=250-e;
F=250-f;
do { Out1 = 1; } while(a--);
do { Out1 = 0; } while(A--);
do { Out2 = 1; } while(b--);
do { Out2 = 0; } while(B--);
do { Out3 = 1; } while(c--);
do { Out3 = 0; } while(C--);
do { Out4 = 1; } while(d--);
do { Out4 = 0; } while(D--);
do { Out5 = 1; } while(e--);
do { Out5 = 0; } while(E--);
do { Out6 = 1; } while(f--);
do { Out6 = 0; } while(F--);
do{ }while(M--);
}
}
main()
{
while(1)
{
SCON = 0x50; //REN=1允许串行接受状态,串口工作模式1
TMOD = 0x20; //定时器工作方式2
PCON = 0x80;
//TH1 = 0xFD; //baud*2 /* reload value 19200、数据位8、停止位1。效验位无 (11.0592)
TH1 = 0xF3; // //baud*2 /* 波特率4800、数据位8、停止位1。效验位无 (12M)
TL1 = 0xF3;
TR1 = 1;
ES = 1; //开串口中断
EA = 1; // 开总中断
while(1)
{
if(RI)
{
RI=0;
m=SBUF-48;
if(m==1)
{
if(a<=120) a=a+3;
else a=a+1;
}
if(m==2)
{
if(a>=180)a=a-3;
else a=a-1;
}
if(m==3) b=b+1;
if(m==4) b=b-1;
if(m==5) c=c+1;
if(m==6) c=c-1;
if(m==7) d=d+1;
if(m==8) d=d-1;
if(m==9) e=e+1;
if(m==0) e=e-1;
if(a<=69) a=69;
if(a>=229) a=228;
if(b<=69) b=69;
if(b>=229) b=228;
if(c<=69) b=69;
if(c>=229) b=228;
if(d<=69) b=69;
if(d>=229) b=228;
if(e<=69) b=69;
if(e>=229) b=228;
}
else
{
PWM(100,130,120,130,140,110);
delay_nms(1000);
PWM(130,150,130,150,150,130);
delay_nms(1000);
PWM(140,170,150,160,170,160);
delay_nms(1000);
PWM(160,175,170,180,180,180);
delay_nms(1000);
PWM(200,180,190,180,190,190);
delay_nms(1000);
PWM(160,175,170,180,180,180);
delay_nms(1000);
PWM(140,170,150,160,170,160);
delay_nms(1000);
PWM(130,150,130,150,150,130);
delay_nms(1000);
PWM(100,130,120,130,140,110);
delay_nms(1000);
}
}
}