always@(posedge clk)
begin
//
if(d1)begin
des[1]<=1; if(low>1||low==2'b00)low<=1; end
if(d2)begin
des[2]<=1;if(high<2&&{d3,d4}==2'b00)high<=2;if((low>2||low==2'b00)&&!d1)low<=1;end
if(d3)begin
des[3]<=1;if(high<3&&!d4)high<=3;if((low>3||low==2'b00)&&{d1,d2}==2'b00)low<=3;end
if(d4)begin des[4]<=1;if(high<4)high<=4;end
//
if({o1,o2,o3,o4}==4'b0000)
begin
{o1,o2,o3,o4}<=4'b1000;
fl<=1;
end
else if(count==3'b101)
begin
count<=0;
door<=0;
if(low==fl)
low<=2'b00;
if(high==fl)
high<=2'b00;
end
else if(count!=0)
begin
count<=count+1;
door<=1;
end
else if(o1&&des[1])
begin
count<=1;
des[1]<=0;
end
else if(o2&&des[2])
begin
count<=1;
des[2]<=0;
end
else if(o3&&des[3])
begin
count<=1;
des[3]<=0;
end
else if(o4&&des[4])
begin
count<=1;
des[4]<=0;
end
//
else if(up)
begin
if(fl
begin
{o1,o2,o3,o4}<={o1,o2,o3,o4}>>1;
fl<=fl+1;
end
else
begin
if(low!=2'b00&&low
begin
if(high>fl&&high-fl
up<=1;
else
down<=1;
end
else if(high>fl)
up<=1;
end
//**************
end
end module
up<=0;
end
//
else if(down)
begin
if(fl>low&&low!=2'b00)
begin
{o1,o2,o3,o4}<={o1,o2,o3,o4}<<1;
fl<=fl-1;
end
else
down<=0;
end
else
//**************