module Motor_Control(
					  Reset,
					  En,
					  Up_En,
					  Down_En,
					  Floor_Time,
					  Now_Floor,
					  Now_Direction,
					  Motor_Data
					  );
input  Reset;
input  En;
input  Up_En;
input  Down_En;
input  Floor_Time; //上下一层楼的时间
output [3:0] Now_Floor; //当前楼层
output [1:0] Now_Direction; //当前电梯方向：上升/下降 10--上升；01--下降
output [1:0] Motor_Data; //电机运行：10--上升；01--下降

reg [3:0] Now_Floor;
reg [1:0] Now_Direction;
reg [1:0] Motor_Data;

always @(posedge Floor_Time)
begin
  if((Reset == 1'b1) || (En == 1'b1))
    begin 
      Now_Floor <= 4'b0;
      Now_Direction <= 2'b0;
      Motor_Data <= 2'b0;
    end
  else
    begin
      if(Up_En == 1'b1)
        begin
          Now_Direction <= 2'b10;  // 上升
          Motor_Data <= 2'b10;
          if(Now_Floor < 4'b1001)
            Now_Floor <= Now_Floor + 4'b1;          
        end
      else if(Down_En == 1'b1)
        begin
          Now_Direction <= 2'b01;  // 下降
          Motor_Data <= 2'b01;
          if(Now_Floor > 4'b0001)
            Now_Floor <= Now_Floor - 4'b1;
        end
      else
        begin
          Now_Direction <= 2'b0; // 停止
          Motor_Data <= 2'b0;
        end
    end
end

endmodule