当前位置:   article > 正文

FPGA入门学习—8位LED跑马灯设计_fpga 8位彩灯设计

fpga 8位彩灯设计

FPGA入门学习—8位LED跑马灯设计:

  • 在Verilog HDL的描述中,状态较少的电路适合用if…else…语句来描述,而状态较多的电路适合用case语句来描述

module设计文件:

`timescale 1ns / 1ps
module LED_Run_Horse(
    input clk,
    input rst_n,
    output reg [7:0]LED
    );
    //璺戦┈鐏?鏁堟灉(15绉嶇姸鎬?)
    //8'b0000_0000    0 鍏ㄧ伃

    //8'b0000_0001    1
    //8'b0000_0010    2
    //8'b0000_0100    3
    //8'b0000_1000    4
    //8'b0001_0000    5
    //8'b0010_0000    6
    //8'b0100_0000    7
    //8'b1000_0000    8
    //8'b0100_0000    9
    //8'b0010_0000    10
    //8'b0001_0000    11
    //8'b0000_1000    12
    //8'b0000_0100    13
    //8'b0000_0010    14
    //8'b0000_0001    15
    //...
    reg [3:0] state;
    always @(posedge clk or negedge rst_n) begin
        if(!rst_n)
            state <= 4'd0;
        else if(state == 4'd16)
            state <= 4'd1;
        else if(state == 4'd0)
            state <= 4'd1;
        else
            state <= state + 1'd1;
    end
    always @(posedge clk or negedge rst_n) begin
        if(!rst_n)begin
                LED <= 8'd0;
            end
        else
            case (state)
                4'd1: LED <= 8'b0000_0001;
                4'd2: LED <= 8'b0000_0010;
                4'd3: LED <= 8'b0000_0100;
                4'd4: LED <= 8'b0000_1000;
                4'd5: LED <= 8'b0001_0000;
                4'd6: LED <= 8'b0010_0000;
                4'd7: LED <= 8'b0100_0000;
                4'd8: LED <= 8'b1000_0000;
                4'd9: LED <= 8'b0100_0000;
                4'd10: LED <= 8'b0010_0000;
                4'd11: LED <= 8'b0001_0000;
                4'd12: LED <= 8'b0000_1000;
                4'd13: LED <= 8'b0000_0100;
                4'd14: LED <= 8'b0000_0010;
                4'd15: LED <= 8'b0000_0001;
                default: LED <= 8'd0;
            endcase
    end
endmodule
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

module仿真文件:

`timescale 1ns / 1ps
module tb_LED_Run_Horse;
reg clk;
reg rst_n;
wire [7:0] LED;
initial begin
clk = 0;
rst_n = 0;
#200; rst_n = 1;
end
always#20 clk = ~clk;
LED_Run_Horse u_LED_Run_Horse(
	.clk(clk),
	.rst_n(rst_n),
	.LED(LED)
);
endmodule
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

仿真波形图:
在这里插入图片描述

综合原理图:
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/699671
推荐阅读
相关标签
  

闽ICP备14008679号