FPGA:D触发器计数器(计数范围:0-99,可暂停、继续、清零)
module Counter(clk, rst, in0, count0,Light0) ;//计数器模块,in循环控制暂停开始
parameter n=5 ;
input rst, clk ,in0;
output [n-1:0] count0 ;
output Light0;
reg [n-1:0] next0 ;
always@(*)
begin
if (count0>=99)//计数器计数范围为0-99,记到99时停止计数
next0= rst? 0 : count0;
else//rst复位信号有效,计数清零。in输入高电平时暂停,in变低后继续计数。
next0= rst? 0 : (in0? count0 : count0+ 1'b1 );
end
assign Light0=rst | in0;//清零或暂停时LED亮起以做提示。
DFF_SW #(n) cnt0(clk, next0, count0) ;
endmodule