module Lift_Run_Manage(
						Reset,
						En,
						Now_Floor,
						Now_Direction,
						Master_Floor1,
						Master_Floor2,
						Master_Floor3,
						Master_Floor4,
						Master_Floor5,
						Master_Floor6,
						Master_Floor7,
						Master_Floor8,
						Master_Floor9,
						Slave_Floor1,
						Slave_Floor2,
						Slave_Floor3,
						Slave_Floor4,
						Slave_Floor5,
						Slave_Floor6,
						Slave_Floor7,
						Slave_Floor8,
						Slave_Floor9,
						Up_En,
						Down_En
						);
input  Reset;
input  En;
input  [3:0] Now_Floor;
input  [1:0] Now_Direction; //10--上升；01--下降

input  Master_Floor1; //"1"--有请求;"0"--无请求
input  Master_Floor2;
input  Master_Floor3;
input  Master_Floor4;
input  Master_Floor5;
input  Master_Floor6;
input  Master_Floor7;
input  Master_Floor8;
input  Master_Floor9;

input  [4:0]Slave_Floor1; //[2]--"1":有请求; "0":无请求 
input  [4:0]Slave_Floor2; //[1:0]-- "01":上升请求; "10":下降请求
input  [4:0]Slave_Floor3;
input  [4:0]Slave_Floor4;
input  [4:0]Slave_Floor5;
input  [4:0]Slave_Floor6;
input  [4:0]Slave_Floor7;
input  [4:0]Slave_Floor8;
input  [4:0]Slave_Floor9;

output Up_En;
output Down_En;

reg Up_En;
reg Down_En;

always @(Reset or En
		  or Now_Floor or Now_Direction
		  or Master_Floor1 or Master_Floor2 or Master_Floor3
		  or Master_Floor4 or Master_Floor5 or Master_Floor6
		  or Master_Floor7 or Master_Floor8 or Master_Floor9
		  or Slave_Floor1 or Slave_Floor2 or Slave_Floor3
		  or Slave_Floor4 or Slave_Floor5 or Slave_Floor6
		  or Slave_Floor7 or Slave_Floor8 or Slave_Floor9
		  or Up_En or Down_En)
begin
  if( (Reset == 1'b1) || (En == 1'b1) )
    begin
      Up_En   <= 1'b0;
      Down_En <= 1'b0;
    end
  else
    begin
      if( ( (Master_Floor2 == 1'b1) && (Now_Floor < 4'b0010) && (Now_Direction == 2'b10) ) ||
          ( (Master_Floor3 == 1'b1) && (Now_Floor < 4'b0011) && (Now_Direction == 2'b10) ) ||
          ( (Master_Floor4 == 1'b1) && (Now_Floor < 4'b0100) && (Now_Direction == 2'b10) ) ||
          ( (Master_Floor5 == 1'b1) && (Now_Floor < 4'b0101) && (Now_Direction == 2'b10) ) ||
          ( (Master_Floor6 == 1'b1) && (Now_Floor < 4'b0110) && (Now_Direction == 2'b10) ) ||
          ( (Master_Floor7 == 1'b1) && (Now_Floor < 4'b0111) && (Now_Direction == 2'b10) ) ||
          ( (Master_Floor8 == 1'b1) && (Now_Floor < 4'b1000) && (Now_Direction == 2'b10) ) ||
          ( (Master_Floor9 == 1'b1) && (Now_Floor < 4'b1001) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor2 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b0010) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor3 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b0011) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor4 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b0100) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor5 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b0101) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor6 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b0110) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor7 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b0111) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor8 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b1000) && (Now_Direction == 2'b10) ) ||
          ( ((Slave_Floor9 & 5'b11100) == 5'b11000 ) && (Now_Floor < 4'b1001) && (Now_Direction == 2'b10) ) ||
          (Now_Floor == 4'b0001) )
        Up_En <= 1'b1;
      else if( ( (Master_Floor1 == 1'b1) && (Now_Floor > 4'b0001) && (Now_Direction == 2'b01) ) ||
               ( (Master_Floor2 == 1'b1) && (Now_Floor > 4'b0010) && (Now_Direction == 2'b01) ) ||
          	   ( (Master_Floor3 == 1'b1) && (Now_Floor > 4'b0011) && (Now_Direction == 2'b01) ) ||
               ( (Master_Floor4 == 1'b1) && (Now_Floor > 4'b0100) && (Now_Direction == 2'b01) ) ||
               ( (Master_Floor5 == 1'b1) && (Now_Floor > 4'b0101) && (Now_Direction == 2'b01) ) ||
               ( (Master_Floor6 == 1'b1) && (Now_Floor > 4'b0110) && (Now_Direction == 2'b01) ) ||
               ( (Master_Floor7 == 1'b1) && (Now_Floor > 4'b0111) && (Now_Direction == 2'b01) ) ||
               ( (Master_Floor8 == 1'b1) && (Now_Floor > 4'b1000) && (Now_Direction == 2'b01) ) ||
               ( ((Slave_Floor1 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b0001) && (Now_Direction == 2'b01) ) || 
               ( ((Slave_Floor2 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b0010) && (Now_Direction == 2'b01) ) ||
               ( ((Slave_Floor3 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b0011) && (Now_Direction == 2'b01) ) ||
               ( ((Slave_Floor4 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b0100) && (Now_Direction == 2'b01) ) ||
               ( ((Slave_Floor5 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b0101) && (Now_Direction == 2'b01) ) ||
               ( ((Slave_Floor6 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b0110) && (Now_Direction == 2'b01) ) ||
               ( ((Slave_Floor7 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b0111) && (Now_Direction == 2'b01) ) ||
               ( ((Slave_Floor8 & 5'b10011) == 5'b10001 ) && (Now_Floor > 4'b1000) && (Now_Direction == 2'b01) ) ||
			   (Now_Floor == 4'b1001) )
        Down_En <= 1'b1;
      else
        begin
          Up_En <= 1'b0;
          Down_En <= 1'b0;
        end
    end
end

endmodule