module MasterSlave_JK_Flip_Flop(j,k,reset,clk,q,qbar);
input j,k,clk,reset;
output q,qbar;
Master M1(j,k,reset,clk,qx,qbarx);
Master S2(qx,qbarx,reset,!clk,q,qbar);
endmodule
//===========================
module Master(j,k,reset,clk,q,qbar);
input j,k,reset,clk;
output reg q,qbar;
initial
q = 0;
always @(posedge clk)begin
if(~reset)begin
case ({j,k})
2'b00:begin
q = q;
qbar = qbar;
end
2'b01:begin
q = 1'b0;
qbar =1'b1;
end
2'b10:begin
q = 1'b1;
qbar =1'b0;
end
2'b11:begin
q = ~ q;
qbar =~qbar;
end
endcase
end
else begin
q <= 1'bz;
qbar <= 1'bz;
end
end
endmodule
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
// Inputs
reg clk=1,reset=0,j=1,k=0;
// Outputs
wire q,qbar;
// Instantiate the Unit Under Test (UUT)
//MasterSlave_JK_Flip_Flop(j,k,reset,clk,q,qbar);
MasterSlave_JK_Flip_Flop UUT(
.j(j),
.k(k),
.reset(reset),
.clk(clk),
.q(q),
.qbar(qbar) );
initial begin
$monitor(j,k,reset,clk,q,qbar);
// Initialize Inputs
#25 j=1;k=1;
#25 j=1;k=0;
#25 j=1;k=1;
#25 j=0;k=1;
#25 j=1;k=1;
#25 j=0;k=0;
#25 j=1;k=1;
#25 j=1;k=0;
#25 j=1;k=1;
reset=1;
#25 j=1;k=0;
#25 j=1;k=1;
#25 j=0;k=1;
reset=0;
#25 j=1;k=1;
#25 j=0;k=0;
#25 j=1;k=1;
#25 j=1;k=0;
end
always #10 clk<=~clk;
initial begin
#440; // 模擬終止時間 440 ns
$stop;
end
endmodule
沒有留言:
張貼留言