1.原理
2.代码
2.1 seg_595_dynamic.v
module seg_595_dynamic(
input wire sys_clk ,
input wire sys_rst_n ,
input wire[19:0] data ,
input wire[5:0] point ,
input wire sign ,
input wire seg_en ,
output wire ds ,
output wire oe ,
output wire shcp ,
output wire stcp
);
wire [15:0] sel;
wire [7:0] seg;
seg_dynamic seg_dynamic_inst(
.sys_clk (sys_clk ) ,
.sys_rst_n (sys_rst_n ),
.data (data ),
.point (point ),
.sign (sign ),
.seg_en (seg_en ),
.seg (seg ) ,
.sel (sel )
);
hc595_ctrl hc595_ctrl_inst(
.sys_clk (sys_clk ) ,
.sys_rst_n (sys_rst_n ),
.sel (sel ) ,
.seg (seg ) ,
.ds (ds ),
.shcp (shcp ),
.stcp (stcp ),
.oe (oe )
);
endmodule
2.2 top_seg_595.v
module top_seg_595(
input wire sys_clk ,
input wire sys_rst_n ,
output wire ds ,
output wire oe ,
output wire shcp ,
output wire stcp
);
wire [19:0] data;
wire [5:0] point;
wire sign;
wire seg_en;
data_gen#(
.CNT_MAX (23'd4999_999),
.DATA_MAX (20'd999_999)
)
data_gen_inst
(
.sys_clk (sys_clk ) ,
.sys_rst_n (sys_rst_n ),
.data (data ),
.point (point ),
.sign (sign ),
.seg_en (seg_en )
);
seg_595_dynamic seg_595_dynamic_inst(
.sys_clk (sys_clk ) ,
.sys_rst_n (sys_rst_n ),
.data (data ),
.point (point ),
.sign (sign ),
.seg_en (seg_en ),
.ds (ds ),
.oe (oe ),
.shcp (shcp ),
.stcp ( stcp )
);
endmodule
2.3 tb_top_seg_595.v
`timescale 1ns/1ns
module tb_top_seg_595();
reg sys_clk;
reg sys_rst_n;
wire ds ;
wire oe ;
wire shcp ;
wire stcp ;
initial
begin
sys_clk=1'b1;
sys_rst_n<=1'b0;
#20
sys_rst_n<=1'b1;
end
always #10 sys_clk=~sys_clk;
defparam top_seg_595_inst.data_gen_inst.CNT_MAX=23'd49;
defparam top_seg_595_inst.seg_595_dynamic_inst.seg_dynamic_inst.CNT_MAX=16'd19;
top_seg_595 top_seg_595_inst(
.sys_clk (sys_clk ) ,
.sys_rst_n (sys_rst_n ),
.ds (ds ),
.oe (oe ),
.shcp (shcp ),
.stcp (stcp )
);
endmodule
ds信号一致