⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 电梯控制程序.txt

📁 把程序写进单片机从而控制电梯的上下
💻 TXT
字号:

#include "reg51.h"
#include "absacc.h"
#define uchar unsigned char
#define uint  unsigned int
sbit dooropen=P1^7;        //输出     
sbit doorshut=P1^2;                   
sbit liftup=P1^1;                      
sbit liftdown=P1^6;                   
sbit onexuanshow=P1^5;              
sbit twoxuanshow=P0^0;
sbit thrxuanshow=P1^4;              
sbit fourxuanshow=P0^1;
sbit ling=P2^0;
sbit oneupshow=P2^7;
sbit twoupshow=P0^7;
sbit thrupshow=P2^6;
sbit twodownshow=P0^6;
sbit thrdownshow=P2^5;
sbit fourdownshow=P0^5;
sbit upshow=P2^4;
sbit downshow=P0^4;
sbit oneshow=P2^3;
sbit twoshow=P0^3;
sbit thrshow=P2^2;
sbit fourshow=P0^2;
uchar bdata Data[5];
sbit open=Data[1]^3;				//输入
sbit shut=Data[1]^4;
sbit opensingal=Data[1]^2;  //
sbit shutsingal=Data[1]^5;    
sbit oneup=Data[1]^0;
sbit twoup=Data[1]^7;     
sbit thrup=Data[2]^7;
sbit twodown=Data[2]^0;  
sbit thrdown=Data[2]^6;
sbit fourdown=Data[2]^1;  
sbit onexuan=Data[3]^3;
sbit twoxuan=Data[3]^4;
sbit thrxuan=Data[3]^2;
sbit fourxuan=Data[3]^5;
sbit onesgl=Data[3]^0;
sbit oneupsgl=Data[3]^7;
sbit twoupsgl=Data[4]^0;     
sbit twosgl=Data[4]^7;
sbit thrupsgl=Data[4]^1;       
sbit thrsgl=Data[4]^6;
sbit fourupsgl=Data[4]^2;       
sbit foursgl=Data[4]^5;      

uchar bdata dta;
sbit load=P3^5; 
sbit clkin=P3^4; 
sbit clk=P3^7;
sbit da=P3^6;                        
sbit di=dta^0;
uchar flag,flag1;
#define void door_open();       
void dushu()
{uchar i,j;  //信号输入
 load=1; clkin=1;
 load=0; clk=0;clk=1;clk=0;
 load=1; ;clkin=0;
 for(i=4;i>0;i--)
 { for(j=8;j>0;j--)
    {
     clk=0; 
     dta=dta<<1;
     di=~da;
     clk=1;
    }
   Data[i]=dta;dta=0;
 }
if(oneup==1) {oneupshow=1;}
 if(twoup==1) {twoupshow=1;}
 if(thrup==1) {thrupshow=1;}
 if(twodown==1) {twodownshow=1;}
 if(thrdown==1) {thrdownshow=1;}
 if(fourdown==1) {fourdownshow=1;}
 if(onexuan==1) {onexuanshow=0;}
 if(twoxuan==1) {twoxuanshow=1;}
 if(thrxuan==1) {thrxuanshow=0;}
else if(fourxuan==1) {fourxuanshow=1;} 
    
}
void dely()
{uint i,j;
 for (i=50000;i>0;i--)
  for(j=6;j>0;j--)
   {;}
}  
void dely1()
{uint i,j;
 for (i=50000;i>0;i--)
  for(j=1;j>0;j--)
   {;}
} 
void baozhan()     //报站
{ling=1;dely1();ling=0;
}
void door_shut()
{dooropen=1;
 doorshut=0;
 dely();
 doorshut=1;
}  
void door_open()
     {doorshut=1;
      dooropen=0;
      dely();
      dooropen=1;
     }
void door()            //开关门
{door_open();
 dely1();
 door_shut();
} 

void lift_up()         //电梯上行
{liftup=0;oneshow=0;flag=1;upshow=1;dely1();
  while(flag==1) 
  {dushu();
   if(twosgl==1&&twoupsgl==1) {twoshow=1;thrshow=0;flag=0;}
   if(thrsgl==1&&thrupsgl==1) {thrshow=1;twoshow=0;flag=0;}
   if(fourupsgl==1) {fourshow=1;thrshow=0;twoshow=0;flag=0;}
  }
 liftup=1;upshow=0;
}  
void lift_down()          //电梯下行
{liftdown=0;fourshow=0;flag=1;downshow=1;dely1();
  while(flag==1) 
  {  dushu(); 
     if(thrsgl==1&&thrupsgl==1) {thrshow=1;twoshow=0;oneshow=0;flag=0;}
     if(twosgl==1&&twoupsgl==1) {twoshow=1;oneshow=0;thrshow=0;flag=0;}
     if(onesgl==1&&oneupsgl==1) {oneshow=1;twoshow=0;thrshow=0;flag=0;}
  }
  liftdown=1;downshow=0;
 }        
void upxuan()                //上选
{  flag1=1;
   while(twoxuanshow==0&&fourxuanshow==0&&thrxuanshow==1) 
	      {dushu();}
   if(twoxuanshow==1) {upshow=1;oneupshow=0;lift_up();baozhan();door();twoxuanshow=0;upshow=0;}
   if(thrxuanshow==0) {upshow=1;if(oneshow==1) {oneupshow=0;lift_up();}
	                             else if(twoshow==1) {twoupshow=0;} 
                       lift_up();baozhan();door();thrxuanshow=1;upshow=0;    
							 }                                  										     
   if(fourxuanshow==1) {upshow=1;if(oneshow==1) {oneupshow=0;lift_up();lift_up();}
	                              else if(twoshow==1) {twoupshow=0;lift_up();}
							   lift_up();baozhan();door();fourxuanshow=0;upshow=0;
							  }	 
}  
downxuan()                       //下选
{ flag1=1;
  while(onexuanshow==1&&twoxuanshow==0&&thrxuanshow==1) 
	      {dushu();}
  if(thrxuanshow==0) {downshow=1;fourdownshow=0;lift_down();baozhan();door();thrxuanshow=1;downshow=0;}
  if(twoxuanshow==1) {downshow=1;  if(fourshow==1) {fourdownshow=0;lift_down();} 
                                    if(thrshow==1) {thrdownshow=0;}
				    lift_down();baozhan();door();twoxuanshow=0;downshow=0;
                     }
  if(onexuanshow==0) {downshow=1; if(fourshow==1) {fourdownshow=0;lift_down();lift_down();} 
                                  else if(thrshow==1) {thrdownshow=0;lift_down();}
                      lift_down();baozhan();door();downshow=0;onexuanshow=1;
                     }  
}     

void main()
{  P0=0;P1=0xff;P2=0;flag=0;flag1=1;
 dushu();
 if(fourupsgl==1) {fourshow=1;thrshow=0;oneshow=0;twoshow=0;}   //判断所在层
  else if(thrsgl==1||thrupsgl==1) {thrshow=1;fourshow=0;oneshow=0;twoshow=0;}
  else if(twosgl==1||twoupsgl==1) {thrshow=0;fourshow=0;oneshow=0;twoshow=1;lift_down();}
  else if(onesgl==1) {thrshow=0;fourshow=0;oneshow=1;twoshow=0;}
 door();
 while(flag1==1)
  {dushu();
   if(oneupshow==1||twoupshow==1||thrupshow==1)
   {flag1=0;
    if(oneupshow==1)   {if(twoshow==1)  {lift_down();} 
	                     else if(thrshow==1) {lift_down();lift_down();}
		             else if(fourshow==1){lift_down();lift_down();lift_down();}
                             oneupshow=0;
							  }
    if(twoupshow==1) {if(oneshow==1) {lift_up();}
	             		 else if(thrshow==1) {lift_down();}
				 else if(fourshow==1) {lift_down();lift_down();} 
                             twoupshow=0;                     
	                  }

    if(thrupshow==1) {if(oneshow==1) {lift_up();lift_up();}
					 if(twoshow==1) {lift_up();}
				   	 if(fourshow==1) {lift_down();}
                             thrupshow=0;                      
	                  } 
    door();upxuan();         //呼车后上选
	}  
  if(twodownshow==1||thrdownshow==1||fourdownshow==1)
	{flag1=0;
         if(twodownshow==1) {if(oneshow==1) {lift_up();}
				else if(thrshow==1) {lift_down();}								               
				else if(fourshow==1) {lift_down();lift_down();} 
                               twodownshow=0;                       
	                    }
	 if(thrdownshow==1) {if(oneshow==1) {lift_up();lift_up();}	                    
				else if(twoshow==1) {lift_up();}
				else if(fourshow==1) {lift_down();}
                                thrdownshow=0;
							  }
       if(fourdownshow==1) {if(oneshow==1) {lift_up();lift_up();lift_up();}
				 else if(twoshow==1) {lift_up();lift_up();}
			     	 else if(thrshow==1) {lift_up();}
                                 fourdownshow=0;								 
	                     } 
   door();downxuan();         //呼车后下选
	} 
 }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -