四种模式循环显示LED流水灯设计.pdf
多种模式的 LED 流水灯设计 1.1.实现的功能要求实现的功能要求 包含四种模式,分别是从左到右点亮,从右到左点亮,从两边到中间点亮,从中间到两边点亮。要求四种模式依次切换,循环执行。2.实现的实现的 HDL 代码代码 module led_run(clk,led,rst);input clk;/clk with low frequency like 1Hz input rst;/system reset signal output 11:0 led;/denotes 12 leds,reg 11:0 led;reg 2:0 state;/state variable,internal signals reg 5:0 count;/control signals of the state diagram,internal signals always(posedge clk or posedge rst)/the state diagram if(rst)begin state=3b000;count=6b000000;end else case(state)3b000:begin count3:0=4b0;count5:4=count5:4+1b1;case(count5:4)2b00:state=3b001;2b01:state=3b010;2b10:state=3b011;2b11:state=3b100;endcase end 3b001:begin count=count+1b1;if(count3:0=11)state=3b000;end 3b010:begin count=count+1b1;if(count3:0=11)state=3b000;end 3b011:begin count=count+1b1;if(count3:0=5)state=3b000;end 3b100:begin count=count+1b1;if(count3:0=5)state=3b000;end default:begin state=3b000;count=6b000000;end endcase always(posedge clk or posedge rst)/the behavior of each state if(rst)led=12hFFF;else case(state)3b000:led=12hfff;3b001:led=led 1;3b010:led 1;3b011:begin led11:61;led5:0=led5:01;end 3b100:begin led11:6=led11:61;led5:01;end default:led=12hfff;endcase endmodule 3.实现的功能仿真截图 经 Modelsim_altera 仿真后的结果如下图所示:(注 led 低电平为亮,高电平为灭)。