//让LED灯按照亮0.25秒,灭0.5秒,亮0.75秒,灭1秒的状态循环亮灭。 源代码 module counter_led_2( clk, reset_n, led ); input clk; input reset_n; output reg led; parameter MCNT=125000000; reg [25:0] counter; always@(posedge clk or negedge reset_n) if(!reset_n) counter<=0; else if(counter==MCNT-1) counter<=0; else counter<=counter+1'b1; always@(posedge clk or negedge reset_n) if(!reset_n) led<=1; else if(counter==(MCNT/10)-1) led<=0; else if(counter==(MCNT/10+MCNT/5)-1) led<=1; else if(counter==(MCNT/10+MCNT/5)*2-1) led<=0; else if(counter==MCNT-1) led<=1; endmodule 仿真代码 `timescale 1ns/1ns module counter_led_2_tb(); reg clk; reg reset_n; wire led; defparam counter_led_2_inst0.MCNT=125000; counter_led_2 counter_led_2_inst0( .clk(clk), .reset_n(reset_n), .led(led) ); initial clk=1; always #10 clk=!clk; initial begin reset_n=0; #201; reset_n=1; #2000000000; $stop; end endmodule
标签:reset,led,clk,器到,counter,LED,小梅哥 From: https://www.cnblogs.com/wangwin4/p/17113374.html