FPGA入门练习
+ -

Verilog计数器练习

2024-04-30 25 0

计数器代码:

`timescale 1ns / 1ps


module cnt(input clk,input rst,output reg [7:0] cnt,output reg plus   );

always@(posedge clk)
begin
    if(!rst)
        cnt <=0;
    else if(cnt==9)
        cnt<=0;
    else 
        cnt<= cnt+1;
end

always@(posedge clk)
begin
    if(!rst)
        plus<=0;
     else if(cnt==9)
        plus<=1;
      else
        plus <=0;
end

endmodule

仿真代码:

`timescale 1ns / 1ps


module cnt_tb( );
reg clk;
reg rst;

wire[7:0] cnt;
wire plus;


cnt cnt_init(.clk(clk),.rst(rst),.cnt(cnt),.plus(plus));

initial
begin
    clk <=0;
    rst <= 0;

    #20
    rst <=1;
end

always #5 clk =~clk;

endmodule

仿真结果:
计数器

0 篇笔记 写笔记

关注公众号
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!