dynamic_hex.v

来自「使用FPGA控制数码管,在数码管上动态的显示数字,很使用,可以直接作为其他模块的」· Verilog 代码 · 共 56 行

V
56
字号

module dynamic_hex(
    hex,
    segcode,
    
    clk,
    rst_n,
    data,
    dot
    );

output  reg [3 :0]  hex;
output  reg [4 :0]  segcode;   

input               clk;
input               rst_n;    
input       [15:0]  data;
input       [3 :0]  dot;
    
  reg     [29:0]  cnt     ;
  always @ ( posedge clk or negedge rst_n )
    if (!rst_n) 
        cnt <= 30'd0;
    else 
        cnt <= cnt + 1'b1;

  always @ ( * )
	case(cnt[19:18])
		2'b00: 
		    begin
		        hex     = data[15:12];
		        segcode = {4'b0111,dot[3]};
		    end
		2'b01:
		    begin
		        hex     = data[11:8];
		        segcode = {4'b1011,dot[2]};
		    end
		2'b10:
		    begin
		        hex     = data[7:4];
		        segcode = {4'b1101,dot[1]};
		    end
		2'b11:
		    begin
		        hex     = data[3:0];
		        segcode = {4'b1110,dot[0]};
		    end
		default:
		    begin 
		        hex     = 4'h0;	
		        segcode = 5'hf; 
		    end
	endcase
endmodule

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?