我们老师要就模拟3层的电梯
麻烦大家帮忙看看
哪里出错了
//电梯控制器
/*信号定义:
clk:时钟信号
d1,d2,d3,d4:楼层请求信号
o1,o2,o3,o4:楼层与请求信号状态显示
door:开门指示信号
fl:送数码管显示的当前楼层数
*/
module lift(clk,d1,d2,d3,d4,o1,o2,o3,o4,door,fl);
input clk,d1,d2,d3,d4;
output o1,o2,o3,o4,door,fl;
reg o1,o2,o3,o4,door,up,down;
reg[4:1] des;
reg[2:0] count;
reg[3:0] low,high,fl;
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
//**************
楼主程序真牛逼,写的这么乱,还没有注释。 verilog程序比较难搞,建议用modesim仿真一下。