8421BCD码的计数器,计数器要求0~ 999怎么写啊
要用D触发器实现 而且是结构描述的 verilog语言求求大家了给我写一个吧 :$ module cnt_999(
input rst_n,
input clk,
outputwire cnt
);
reg cnt0;
reg cnt1;
reg cnt2;
always @ (posedge clk or negedge)
begin
if (rst_n == 1'b0)
cnt0 <= 4'd0;
else if (cnt0 >= 4'd9)
cnt0 <= 4'd0;
else
cnt0 <= cnt0 + 4'd1;
end
always @ (posedge clk or negedge)
begin
if (rst_n == 1'b0)
cnt1 <= 4'd0;
else if (cnt0 >= 4'd9)
begin
if (cnt1 >= 4'd9)
cnt1 <= 4'd0;
else
cnt1 <= cnt1 + 4'd1;
end
else ;
end
always @ (posedge clk or negedge)
begin
if (rst_n == 1'b0)
cnt1 <= 4'd0;
else if ((cnt0 >= 4'd9) && (cnt1 >= 4'd9))
begin
if (cnt2 >= 4'd9)
cnt2 <= 4'd0;
else
cnt2 <= cnt2 + 4'd1;
end
else ;
end
assign cnt = {cnt2,cnt1,cnt0};
endmodule
不知道这样是不是可以? 还用了个:$,好腼腆啊。。哈哈:$
页:
[1]
