|
这是我做的电梯程序的一部分,出现了几个问题
module dianti(clk,reset,Topen,Tclose,open,close,Oup,Odown,topen,tclose,up,down,anniu2,floor,shu,recode0);
input clk,reset,Topen,Tclose,open,close;//Topen,Tclose:dianti men zhuangtai;open,close:dianti nei anniu
input[0:7] up,down;//up[0]~up[7]:1~8 ceng shangcheng anniu;down[0]~down[7]:1~8 ceng xiajiang anniu
output Oup,Odown,topen,tclose;
output[0:8] recode0;
input[0:7] anniu2,floor,shu;
wire Topen,Tclose,open,close,reset,clk;
wire[0:7] floor,up,down,anniu1,anniu2,shu;
wire tclose1,topen1,Oup,Odown,topen,tclose;
reg[0:8] dt,dt1,dt2;
wire topen2,tclose2;
wire[0:8] recode0, recode1,recode2,recode3,recode4,recode5,recode6,recode7;
wire[0:8] recode01, recode11,recode21,recode31,recode41,recode51,recode61,recode71;
wire[0:8] recode02, recode12,recode22,recode32,recode42,recode52,recode62,recode72;
integer i,j,k;
men a1(reset,clk,close,open,topen2,tclose2,Oup,Odown);
anniu b1(reset,clk,anniu2,recode02, recode12,recode22,recode32,recode42,recode52,recode62,recode72);
zhongzhi c1(reset,clk,Oup,Odown,floor,recode01, recode11,recode21,recode31,recode41,recode51,recode61,recode71,tclose1,topen1);
shangxia d1(reset,clk,Oup,Odown,floor,recode0);
zhihuan e1(reset,clk,up,down,anniu1);
assign tclose=tclose2 || tclose1;
assign topen=topen2 || topen1;
endmodule
module anniu(reset,clk,anniu,recode0, recode1,recode2,recode3,recode4,recode5,recode6,recode7);
input reset,clk;
input[0:7] anniu;
inout[0:8] recode0, recode1,recode2,recode3,recode4,recode5,recode6,recode7;
wire reset,clk;
wire[0:7] anniu;
wire[0:8] recode0, recode1,recode2,recode3,recode4,recode5,recode6,recode7;
reg[0:7] recode[0:8];
integer i,a,b,c;
always @(reset or clk)
begin
a=0;b=0;
if(reset)
for(i=0;i<=7;i=i+1)
recode[i]<=0;
else begin
if(anniu[0]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==1)
b=1;
if(b==0) begin
recode[a]=1;a=a+1; end
end
else if(anniu[1]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==2)
b=1;
if(b==0) begin
recode[a]=2;a=a+1; end
end
else if(anniu[2]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==3)
b=1;
if(b==0) begin
recode[a]=3;a=a+1; end
end
else if(anniu[3]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==4)
b=1;
if(b==0) begin
recode[a]=4;a=a+1; end
end
else if(anniu[4]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==5)
b=1;
if(b==0) begin
recode[a]=5;a=a+1; end
end
else if(anniu[5]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==6)
b=1;
if(b==0) begin
recode[a]=6;a=a+1; end
end
else if(anniu[6]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==7)
b=1;
if(b==0) begin
recode[a]=7;a=a+1; end
end
else if(anniu[7]) begin
for(i=0;i<=7;i=i+1)
if(recode[i]==8)
b=1;
if(b==0) begin
recode[a]=8;a=a+1; end
end
else begin
recode[a]=0;a=a;
end
if(a==7)
a=0;
end
end
assign recode0=recode[0];
assign recode1=recode[1];
assign recode2=recode[2];
assign recode3=recode[3];
assign recode4=recode[4];
assign recode5=recode[5];
assign recode6=recode[6];
assign recode7=recode[7];
endmodule
module zhongzhi(reset,clk,Oup,Odown,floor,recode0, recode1,recode2,recode3,recode4,recode5,recode6,recode7,tclose,topen);
input reset,clk,Oup,Odown;
input[0:7] floor;
output tclose,topen;
inout[0:8] recode0, recode1,recode2,recode3,recode4,recode5,recode6,recode7;
wire[0:8] recode0, recode1,recode2,recode3,recode4,recode5,recode6,recode7;
reg[0:7] recode[0:8];
reg topen,tclose;
integer i,a,b;
always @(reset or clk)
begin
a=0;b=0;
recode[0]=recode0;
recode[1]=recode1;
recode[2]=recode2;
recode[3]=recode3;
recode[4]=recode4;
recode[5]=recode5;
recode[6]=recode6;
recode[7]=recode7;
if(reset) begin
recode[0]=0;
recode[1]=0;
recode[2]=0;
recode[3]=0;
recode[4]=0;
recode[5]=0;
recode[6]=0;
recode[7]=0;end
else begin
if(floor==recode[0])
if(!Oup)
if(!Odown)
begin
topen=1;
tclose=0;
for(i=0;i<=6;i=i+1)
recode[i]=recode[i+1];
end
end
end
assign recode0=recode[0];
assign recode1=recode[1];
assign recode2=recode[2];
assign recode3=recode[3];
assign recode4=recode[4];
assign recode5=recode[5];
assign recode6=recode[6];
assign recode7=recode[7];
endmodule
module men(reset,clk,close,open,topen,tclose,Oup,Odown);
input reset,clk,close,open,Oup,Odown;
output tclose,topen;
reg tclose,topen;
wire reset,clk,close,open,Oup,Odown;
always @(reset or clk)
begin
if(reset)begin
tclose=1;
topen=0;
end
else begin
if((Oup==1)||(Odown==1)) begin
tclose=1;
topen=0;
end
else if((close==1)&&(open==0)) begin
tclose=1;
topen=0;
end
else if((close==0)&&(open==1)) begin
tclose=0;
topen=1;
end
else
begin
tclose=0;
topen=1;
end
end
end
endmodule
module shangxia(reset,clk,Oup,Odown,floor,shu);//panding shangsheng haishi xiajiang
input reset,clk;
input[0:7] floor,shu;
output Oup,Odown;
reg Oup,Odown;
wire[0:7] floor,shu;
integer a,b,i;
always @(reset or clk)
begin
a=0;b=0;
for(i=0;i<=7;i=i+1)
begin
if(floor[i])
a=a+2^i;
if(shu[i])
b=b+2^i;
end
if(reset)begin
Oup=0;
Odown=0;end
else
begin
if(b<a)
begin
Oup=0;
Odown=1;
end
else if(b>a)begin
Oup=1;
Odown=0;end
else begin
Oup=0;
Odown=0;end
end
end
endmodule
module zhihuan(reset,clk,up,down,anniu1);
input reset,clk;
input[0:7] up,down;
output[0:7] anniu1;
reg[0:7] anniu1;
integer i;
always @(reset or clk)
begin
if(reset)
anniu1=0;
else
for(i=0;i<=7;i=i+1)
if(up[i])
anniu1=i;
if(down[i])
anniu1=i;
end
endmodule
1.仿真时inout的端口不连线。
2.如果要anniu能分时间段轮流被anniu1和anniu2赋值该如何做? |
|