天天看点

【FPGA】【Verilog】【基础模块】触发器&锁存器

D触发器:

//D触发器
module dff(q,clk,data);
	output q;
	input data, clk;
	reg q;

	always @(posedge clk)
		begin
			q  = data;
		end

endmodule 
           

    带置位复位:

module dff2(q, qb, d, clk, set, reset);
	input d, clk, set, reset;
	output q, qb;
	
	reg q, qb;

	always @(posedge clk)
		begin 
			if(reset )
				begin 
					q = 0;
					qb = 1;
				end 
			else 
				if(set )
					begin 
						q  = 1;
						qb = 0;
					end
				else 
					begin 
						q = d ;
						qb = ~d;
					end 
		end 
endmodule 
           

锁存器:

    ()?():()实现:

//锁存器
module latch1 (q,data ,clk);
output q;
input data ,clk;

assign q = clk? data : q ;

endmodule
           

    ()?():()实现,带置位复位:

//锁存器
module latch2 (q ,data ,clk,set ,reset );
	input data ,clk,set,reset;
	output q;
	
	assign q = reset ? 0 : 
									( set ? 1 : 
													(clk ? data : q  ));
	endmodule 

           

    if实现:

module latch3(q,data ,clk);
	output q;
	input data ,clk;
	reg q;
	
		always @(clk or data )
			begin
				if(clk)
					q = data ;
			end 
endmodule
 
           

继续阅读