22-数码管的动态显示-头条
2023-07-06
博客园 2023-07-06 05:35:31
【资料图】
使用6位8段数码管显示从0-999999,计数到最大值之后循环显示,每0.1s加1
显示的数据需要一个新的模块产生data_gen
参考数码管静态显示,将seg_595_dynamic模块划分为两个模块,一个是动态显示驱动模块,第二个是595控制模块
module data_gen#( parameter CNT_MAX = 23"d4999_999, parameter DATA_MAX = 20"d999_999)( input wire sys_clk, input wire sys_rst_n, output reg [19:0] data, output wire [5:0] point, output wire sign, output reg seg_en); reg [22:0] cnt_100ms; reg cnt_flag; always @ (posedge sys_clk or negedge sys_rst_clk) if(sys_rst_n == 1"b0) cnt_100ms <= 23"d0; else if(cnt_100ms == CNT_MAX) cnt_100ms <= 23"d0; else cnt_100ms <= 23"d0 + 1"b1; always @ (posedge sys_clk or negedge sys_rst_clk) if(sys_rst_n == 1"b0) cnt_flag <= 1"b0; else if(cnt_100ms == CNT_MAX-1) cnt_flag <= 1"b1; else cnt_flag <= 1"b0; always @ (posedge sys_clk or negedge sys_rst_clk) if(sys_rst_n == 1"b0) data <= 20"d0; else if((data == DATA_MAX)&&(cnt_flag == 1"b1)) data <= 20"d0; else if(cnt_flag == 1"b1) data <= data + 1"b1; else data <= data; // 小数点赋值 assign point = 6"b000_000 // 符号位 assign sign = 1"b0; // 使能信号 always @ (posedge sys_clk or negedge sys_rst_clk) if(sys_rst_n == 1"b0) seg_en <= 1"b0; else seg_en <= 1"b1;endmodule
module tb_data_gen(); input reg sys_clk; input reg sys_rst_n; output wire [19:0] data; output wire [5:0] point; output wire sign; output wire seg_en; always #10 sys_clk = -sys_clk; module data_gen#( .CNT_MAX (23"d4999_999), .DATA_MAX (20"d999_999))( .sys_clk (sys_clk), .sys_rst_n, .data (data), .point (point), .sign (sign), .seg_en (seg_en)); endmodule