Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module JKflipflop(input [1:0] J, K, clock, output reg [1:0] Q, Q2, output Qb, Qb2);
- always @(posedge clock[0]) begin
- case ({J[0],K[0]})
- 2'b00: Q <= Q;
- 2'b01: Q <= 1'b0;
- 2'b10: Q <= 1'b1;
- 2'b11: Q <= !Q;
- endcase
- end
- assign Qb = !Q;
- always @(posedge clock[1]) begin
- case ({J[1],K[1]})
- 2'b00: Q2 <= Q2;
- 2'b01: Q2 <= 1'b0;
- 2'b10: Q2 <= 1'b1;
- 2'b11: Q2 <= !Q2;
- endcase
- end
- assign Qb2 = !Q2;
- endmodule
- module JKflipflopTB;
- reg [1:0] J, K, clock;
- integer h = 0;
- JKflipflop TB(.J(J), .K(K), .clock(clock), .Q(Q), .Q2(Q2), .Qb(Qb), .Qb2(Qb2));
- always #10 clock[0] = !clock[0];
- always #20 clock[1] = !clock[1];
- initial begin
- clock <= 0;
- repeat (4) begin
- {J[0], K[0]} <= h;
- {J[1], K[1]} <= h;
- h = h + 1;
- #10;
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement