FPGA Verilog 4 bit LED 計數器

版权声明:本文为博主 ( 黃彥霖 ) 原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_38884324/article/details/81175428

前言:

計數器每秒 +1,所以LED會以二進制方式表示 0~15 的計數顯示

程式碼:


module led_test
(
   input            clk,           // 系統 50 Mhz 時鐘
   output [3:0]     led            // 板子上有 4 顆 LED,宣告為輸出
);  

    reg [31:0]      timer; // 宣告 32 bit 的整數變數    (計數 Clock, 每一秒清零)
    reg [3:0]       count; // 宣告  4 bit 的整數變數 (之後計數0~15,用於顯示)

    // 每個 Clock 都會觸發
    always@(posedge clk)
    begin         
         // 每個 Clock 將 timer 自動加一
         timer <= timer + 32'd1; 

         // timer 達到 49999999 ( 1秒 ) 時,將 timer 清零
         if(timer == 32'd49_999_999)
            begin
              timer <= 32'd0;
                  count <= count + 4'b1;
            end         
    end

     assign led = ~ count; // 將 count 變數與外部 4 顆 LED 電路連接起來  

endmodule

猜你喜欢

转载自blog.csdn.net/weixin_38884324/article/details/81175428
今日推荐