基本D触发器、同步D触发器和异步D触发器的Verilog描述

时间:2024-03-09 18:45:49
  • //基本D触发器

module D_EF(Q,D,CLK)

input D,CLK;

output Q;

reg Q;                           //在always语句中被赋值的信号要声明为reg类型 寄存器定义

always @ (posedge CLK) //上升沿,下降沿用negedge表示,^_^ 需要记忆

       begin Q <= D; end

endmodule

 

  • //带异步清0、异步置1的D触发器

module D_EF(q,qn,d,clk,set,reset)

input d,clk,set,reset;

output q,qn;

reg q,qn;//寄存器定义

always @ (posedge clk or negedge set or negedge reset)

       begin

              if(!reset) begin q<=0;qn<=1;end//异步清0,低有效

              else if(!set) begin q<=1;qn<=1;end //异步置1,低有效

              else begin q<=~d;qn<=~d;end

       end  

endmodule

 

  • //带同步清0、同步置1的D触发器

module D_EF(q,qn,d,clk,set,reset)

input d,clk,set,reset;

output q,qn;

reg q,qn;

always @ (posedge clk)

       begin

              if(reset) begin q<=0;qn<=1;end//同步清0,高有效

              else if(set) begin q<=1;qn<=1;end //同步置1,高有效

              else begin q<=~d;qn<=~d;end

       end  

endmodule

 

 

转载自SkySeraph,http://www.cnblogs.com/skyseraph/archive/2010/09/24/1834216.html