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