用verilog写一个流水灯
时间: 2023-10-29 19:07:14 浏览: 45
20181060261-李康_quartus_流水灯_fpga_
5星 · 资源好评率100%
下面是一个简单的Verilog代码,实现了流水灯效果:
```
module traffic_light (input clk, output reg red, yellow, green);
parameter delay = 5;
reg [31:0] counter = 0;
always @ (posedge clk) begin
if (counter == delay) begin
counter <= 0;
red <= ~red;
yellow <= ~yellow;
green <= ~green;
end else
counter <= counter + 1;
end
endmodule
```
该代码在每个时钟脉冲上升沿(posedge clk)时执行。如果计数器(counter)等于某个延迟(delay),则将计数器清零,并在红灯,黄灯和绿灯(red,yellow,green)上交替更改电平。
阅读全文