赞
踩
本段代码是为Verilog初学者提供的一个名为led_blink简单实例Verilog模块,其功能是控制6个LED灯同步闪烁,每秒钟闪烁一次。
本例代码用于理解时序逻辑的概念,理解多个always模块完全并行执行的概念,讲授时可以与C语言的执行过程进行比对,特别是分支结构与C语言形式上非常相似。
知识点:
//led_blink_v0.v
//Function: leds blink every second
//Author: Richard Fu
//Date: 2024-04-26
module led_blink(
input clk,
input rst_n,
output wire [5:0] led
);
reg [31:0] count;
//always @(posedge clk or negedge rst_n) begin
always @(posedge clk) begin
if(~rst_n) count <= 0;
else if(count < 50*1000*1000) count <= count + 1;
else count <= 0;
end
reg led_q;
always @(posedge clk) begin
if(~rst_n) led_q <= 6'b000000;
else if(count == 50*1000*1000) begin
if(led_q == 6'b000000) led_q <= 6'b111111;
else led_q <= 6'b000000;
end
//else led_q <= led_q;
end
assign led = led_q;
endmodule
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。