可惜不能传附件
只能传代码
公司电脑真啃爹。
等我回家给大伙弄个视频
先看系代码
#include
sfr ISP_CONTR=0XE7;
unsigned char e;
unsigned int a,b,cm;
sbit a0=P2^0;//上升气缸
sbit a1=P2^1;//滑台气缸
sbit a2=P2^2;//旋转气缸
sbit a3=P2^3;//手指气缸
sbit a4=P2^4;//蜂鸣器
sbit a5=P2^6;//焊接机1自动启动
sbit a6=P2^5;//焊接机2 自动启动
sbit b2=P1^0;//脉冲信号
sbit b3=P1^1;//方向信号
sbit b4=P3^6;//左边到达信号
sbit b7=P3^7;//右边到达信号,复位信号
sbit c0=P1^3;//焊接机1治具开关信号
sbit c1=P1^5;//焊接机1灯信号
sbit c2=P1^4;//焊接机2治具开关信号
sbit c3=P1^6;//焊接机2灯信号
sbit d1=P3^2;
sbit d2=P3^3;
void delay(int x)
{
int a,b;
for(a=x;a>0;a--)
for(b=2000;b>0;b--);
}
void inter_init()
{
EA=1;//开总中断
ET0=1;//开定时器0
TMOD=0X01;//使用方式1
TH0=(65535-120)/256;//定时器赋初值
TH1=(65535-120)%256;//定时器赋初值
TR0=0;
}
void chushihua()
{
a=0;
b=50;
cm=19000;
e=0;
P1=0x00;
P3=0x00;
}
main()
{
inter_init();
chushihua();
while(1)
{
if(b7==1&&e==0)//感应器感应
{
TR0=1;
b3=0;
if(a>=b) //微调
{
TR0=0;
e++;
a=0;
}
}
if(b7==0&&e==0) //感应器未感应
{
TR0=1;
b3=1;
if(b7==1)
{
TR0=0;
delay(50);
TR0=1;
b3=0;
if(a>=b) //微调
{
TR0=0;
e++;
a=0;
}
}
}
if(e==1)
{
delay(50);
TR0=1; //回到待机点
b3=0;
if(a>=4500)
{
TR0=0;
e++;
a=0;
}
}
if(e==2&&c0==1)
{
delay(60);
if(c0==1)
{
e++;
b3=1;
TR0=1;
}
}
if(e==3&&b7==1)
{
TR0=0;
e++;
}
if(e==4&&c0==1&&c1==1) //焊接OK
{
delay(30);
a1=0;//滑台气缸滑出去
delay(50);
a0=0; //上升气缸下降
delay(50);
a3=0;//手指气缸张开
delay(50);
a0=1;//气缸上升
delay(40);
a1=1;
delay(140);
a=0;
e++;
}
if(e==5)
{
TR0=1;
b3=0;
if(a>=cm)//500
{
TR0=0;
d1=1;
a2=0;//旋转
delay(100);
delay(100);
e++;
}
}
if(c2==0&&c3==1&&e==6)//放板
{
delay(60);
if(c2==0&&c3==1)
{
e++;
a=0;
TR0=1;
}
}
if(e==7&&b4==1)//6000
{
TR0=0;
delay(40);
a1=0;
delay(40);
a0=0; //气缸下降
delay(80);
a3=1;
delay(50);
a0=1; //气缸上升
delay(80);
a2=1;//旋转
delay(60);
a6=0;
delay(20);
a6=1;
d2=0;
e++;
a=0;
}
if(e==8)
{
/*TR0=1;
b3=1;
if(a>=10000)
{
TR0=0;
e=2;
}*/
ISP_CONTR=0X20; //信号复位
}
}
}
void time()interrupt 1 using 1
{
TH0=(65535-120)/256;
TL0=(65535-120)%256;
a++;
b2=~b2;
} |