赞
踩
module water_flow_lamp #( parameter MAX_CNT = 25'd24_999_999 ) ( input wire sys_clk , input wire sys_rst_n , output reg [3:0] led_out ); reg [24:0] cnt ; reg cnt_flag ; always@(posedge sys_clk or negedge sys_rst_n) if(sys_rst_n == 1'b0) cnt <= 25'd0 ; else if(cnt == MAX_CNT ) cnt <= 25'd0 ; else cnt <= 25'd1 + cnt ; always@(posedge sys_clk or negedge sys_rst_n) if(sys_rst_n == 1'b0) cnt_flag <= 1'b0 ; else if(cnt == MAX_CNT -25'd1) cnt_flag <= 1'b1 ; else cnt_flag <= 1'b0 ; always@(posedge sys_clk or negedge sys_rst_n) if(sys_rst_n == 1'b0) led_out <= 4'b1110 ; else if(cnt_flag == 1'b1) led_out <= {led_out[2:0], led_out[3]}; //将高位补到末位 else led_out <= led_out ; endmodule
`timescale 1ns/1ns module tb_water_flow_lamp(); reg sys_clk; reg sys_rst_n; wire [3:0] led_out; initial begin sys_clk = 1'b1; sys_rst_n <= 1'b0; #20 sys_rst_n <= 1'b1; end always #10 sys_clk = ~sys_clk; //clk frequency water_flow_lamp #( .MAX_CNT(25'd24) ) water_flow_lamp_inst ( .sys_clk (sys_clk) , .sys_rst_n(sys_rst_n) , .led_out (led_out) ); endmodule
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。