#include <reg52.h> #define uchar unsigned char #define uint unsigned int sbit p10=P1^0; /*摇臂上升键*/ sbit p11=P1^1; /*摇臂下降键*/ sbit p35=P3^5; /*摇臂夹紧到位*/ sbit p34=P3^4; /*摇臂松开到位*/ sbit p01=P0^1; /*油泵电机启动*/ sbit p02=P0^2; /*上升继电器*/ sbit p03=P0^3; /*下降继电器*/ sbit p04=P0^4; /*摇臂松开电磁阀*/ sbit p05=P0^5; /*摇臂夹紧电磁阀*/ void main() { while(1) { if(p10==0) /*摇臂上升按下*/ { delay(200); //延时消抖 if(p10==0) { p01=0; /*启动油泵*/ p04=0; /*摇臂松开电磁阀*/ } } if((p10==0)&&(p34==0)) /*如果摇臂上升按下和摇臂松到位*/ { p04=1; //关闭松开电磁阀 p02=0; /*摇臂上升继电器吸合*/ } if(p10==1) /*松开摇臂夹紧键*/ { p02=1; /*上升继电器停止*/ delay(2000); /*延时2s*/ p05==0; /*夹紧*/ } if(p35==0) /*夹紧到位*/ { p05=1; /*摇臂夹紧电磁阀关*/ p01=1; /*停油泵*/ } } } void delay(uchari) { uchar j; while(i--) { for(j=0;j<125;j++) {;} } }