文档介绍:#include<>
#define uchar unsigned char
/***************------宏定义------*******************/
sbit qigang_left=P0^0; //气缸
sbit qigang_right=P0^1;
sbit qigang_up=P0^2;
sbit qigang_down=P0^3;
sbit qigang_behind=P0^4;
sbit qigang_front=P0^5;
sbit qigang_grasp=P0^6;
sbit qigang_loose=P0^7;
sbit journey_left=P1^0; //传感器开关
sbit journey_right=P1^1;
sbit journey_up=P1^2;
sbit journey_down=P1^3;
sbit journey_behind=P1^4;
sbit journey_front=P1^5;
sbit flag_start=P3^2; //启动按钮
/*************** 中断****************************/
void t0(void) interrupt 0 using 0 //按键按下触发中断服务程序
{
//flag_start=1;
}
/*************** 延时函数S***********************/
void delay(unsigned char m) //延时子m秒子程序
{
unsigned char i,j,k;
m=m*100;
for(i=m;i>0;i--)
for(j=20;j>0;j--)
for(k=248;k>0;k--);
}
/******************* 主函数*********************/
void main()
{
qigang_left=1;
qigang_right=1;
qigang_front=1;
qigang_behind=1;
qigang_up=1;
qigang_down=1;
qigang_grasp=1;
qigang_loose=1;
/*************** 中断初始化******************/
IT0=1; // 下降沿触发
EX0=1;
EA=1;
if(flag_start==0)
{
while(1)
{
qigang_left=0; //机械手左移
while(1) //左移死循环,等待下面的传感器开关
{
if(journey_left==0) //左面的传感器开关接通
{
qigang_left=1; //停止左移
qigang_front=0; //机械手前移
while(1) //前移死循环,等待前面的传感器开关
{
if(journey_front==0) //前面的传感器开关接通
{
qigang_front=1; //停止前移
qigang_down=0;