四位二进制计数器和真值表:
代码如下:
module jishuqi(clk,rst,en,rset,co,d,q);
input clk;
input rst;
input rset;
input en;
input[3:0] d;
output[3:0] q;
output co;
reg[3:0] q;
reg co;
always@(posedge clk)
if(rst)
begin
q <= 4'd0;
end
else
begin
if(rset)
begin
q <= d;
end
else
begin
if(en)
begin
q <= q+4'b1;
if(q==4'b1111)
begin
co <= 1;
end
else
begin
co <= 0;
end
end
else
begin
q <= q;
end
end
end
endmodule
功能仿真: