|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
我要写一个简单的电梯控制verilog。我想问问这样写有什么问题吗?谢谢。
module semester(
input [3:0]w,
input Clock,
input switch,
output first,
output second,
output third,
output fourth
);
reg [2:0] y;
reg [1:0] counter;
initial begin
counter=00;
y=001;
end
parameter [2:0] A = 3'b000, B = 3'b001, C = 3'b010, D= 3'b011,E=3'b100,F=3'b101,G=3'b110,H=3'b111;
always@ (posedge Clock)begin
case (y)
A:
if(w==0001|switch==1) begin
y<=A;
counter=00;
end
else if(!counter==11&(w==0000|w==0010|w==0100|w==1000)&switch==0)
counter=counter+1;
else if(counter==11&(w==0000|w==0010|w==0100|w==1000)&switch==0) begin
y<=B;
counter=00;
end
B:
if(w==0000)
y<=B;
else if(w==0001)
y<=A;
else if((w==0010|w==0100|w==1000)&!counter==01)
counter=counter+1;
else if((w==0010|w==0100|w==1000)&counter==01) begin
y<=D;
counter=00;
end
C:
if(w==0010|switch==1) begin
y<=C;
counter=00;
end
else if((w==0000|w==0001|w==0100|w==1000)&!counter==11&switch==0)
counter=counter+1;
else if((w==0000|w==0001|w==0100|w==1000)&counter==11&switch==0)begin
y<=D;
counter=00;
end
D:
if(w==0000)
y<=D;
else if(w==0010)
y<=C;
else if((w==0001|w==0100|w==1000)&!counter==01)
counter=counter+1;
else if(w==0001&counter==01) begin
y<=B;
counter=00;
end
else if((w==0100|w==1000)&counter==01) begin
y<=F;
counter=00;
end
E:
if(w==0100|switch==1) begin
y<=E;
counter=00;
end
else if((w==0000|w==0001|w==0010|w==0100)&!counter==11&switch==0)
counter=counter+1;
else if((w==0000|w==0001|w==0010|w==0100)&counter==11&switch==0)begin
y<=F;
counter=00;
end
F:
if(w==0000)
y<=F;
else if(w==0100)
y<=E;
else if((w==001|w==0010|w==1000)&!counter==01)
counter=counter+1;
else if((w==0001|w==0010)&counter==01) begin
y<=D;
counter=00;
end
else if(w==1000&counter==01) begin
y<=H;
counter=00;
end
G:
if(w==1000|switch==1) begin
y<=G;
counter=00;
end
else if((w==0000|w==0001|w==0010|w==0100)&!counter==11&switch==0)
counter=counter+1;
else if((w==0000|w==0001|w==0010|w==0100)&counter==11&switch==0) begin
y<=H;
counter=00;
end
H:
if(w==0000)
y<=H;
else if(w==1000)
y<=G;
else if((w==0001|w==0010|w==0100)&!counter==01)
counter=counter+1;
else if((w==0001|w==0010|w==0100)&!counter==01) begin
y<=F;
counter=00;
end
default y<=3'bxxx;
endcase
end
assign first=~y[0]&~y[1]&~y[2];
assign second=!y[0]&y[1]&!y[2];
assign third=!y[0]&!y[1]&y[2];
assign fourth=!y[0]&y[1]&y[2];
endmodule |
|