Skip to content

Instantly share code, notes, and snippets.

Created April 6, 2013 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5325564 to your computer and use it in GitHub Desktop.
Save anonymous/5325564 to your computer and use it in GitHub Desktop.
module RSFlipFlop(not_s, not_r, q);
input not_s, not_r;
output q;
wire not_q;
function NAND;
input x, y;
begin
NAND = ~(x & y);
end
endfunction
assign q = NAND(not_s, not_q);
assign not_q = NAND(not_r, q);
endmodule
module HalfDFlipFlop(in, clk, w1, w2, out);
input in, clk;
output w1, w2, out;
function NAND;
input x, y;
begin
NAND = ~(x & y);
end
endfunction
assign w1 = NAND(in, clk);
assign w2 = NAND(w1, clk);
RSFlipFlop rs1(w1, w2, out);
endmodule
module Tiny(switch, led, dip);
input [1:0] switch;
input [3:0] dip;
output [7:0] led;
reg ff;
wire d, clk, w1, w2, q1, w3, w4, q2;
assign d = dip[0];
assign clk = ~switch[0];
assign led[7] = d;
HalfDFlipFlop hd1(d, ~clk, w1, w2, q1);
assign led[6] = w1;
assign led[5] = w2;
assign led[4] = q1;
HalfDFlipFlop hd2(q1, clk, w3, w4, q2);
assign led[3] = w3;
assign led[2] = w4;
assign led[1] = q2;
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment