第3章 Verilog HDL快速入门(针对FPGA)
verilog
module counter #(
parameter WIDTH = 8 // 位宽参数,可外部修改
)(
input wire clk, // 时钟
input wire rst_n, // 复位,低有效
input wire en, // 使能
output reg [WIDTH-1:0] count // 计数值
);
// 时序逻辑:每个时钟上升沿执行
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
count <= 0;
else if (en)
count <= count + 1'b1;
end
endmodule