使用Quartus-II 9.1SP2 + ModelSim 6.5b-Aletra + Altera DE2-115 FPGA開發平台,設計D Latch為例
module D_Latch(Q, Qn, G, D);
output Q;
output Qn;
input G;
input D;
wire Dn;
wire D1;
wire Dn1;
not(Dn, D);
and(D1, G, D);
and(Dn1, G, Dn);
nor(Qn, D1, Q);
nor(Q, Dn1, Qn);
endmodule
`timescale 10ns/10ps
module D_Latch_tb;
wire q;
wire qn;
reg g;
reg d;
D_Latch DUT(
.Q(q),
.Qn(qn),
.G(g),
.D(d)
);
initial begin
g=1'b1;d=1'b0;
#500 $stop;
end
always begin
#50 g=g+1'b1;
end
always begin
#100 d=d+1'b1;
end
endmodule
output Qn;
input G;
input D;
wire Dn;
wire D1;
wire Dn1;
not(Dn, D);
and(D1, G, D);
and(Dn1, G, Dn);
nor(Qn, D1, Q);
nor(Q, Dn1, Qn);
endmodule
`timescale 10ns/10ps
module D_Latch_tb;
wire q;
wire qn;
reg g;
reg d;
D_Latch DUT(
.Q(q),
.Qn(qn),
.G(g),
.D(d)
);
initial begin
g=1'b1;d=1'b0;
#500 $stop;
end
always begin
#50 g=g+1'b1;
end
always begin
#100 d=d+1'b1;
end
endmodule
沒有留言:
張貼留言