狀態說明:
1, 初始化 東西南北的燈全亮;
2, 東西綠燈亮,南北紅燈亮 20秒;
3, 東西黃燈亮,南北紅燈亮 5秒;
4, 東西紅燈亮,南北綠燈亮 20秒;
5, 東西紅燈亮,南北黃燈亮 5秒;
6, 迴圈 2,3,4,5,
**如下:
`timescale 1ns/1ps
// company :
// author : gong
// create date : 2012.8.24
// design name :
// module name : traffic
// project name : traffic
// target device: cycloneii ep2c8q208c8
// tool versions: quartusii 9.0
// description :
// revision : v1.0
// additional comments :
//紅黃綠
//1亮0滅
module traffic (
clk,
rst_n,
dongxi,
nanbei
);input clk;
input rst_n;
output [2:0] dongxi;
output [2:0] nanbei;
reg [2:0] dongxi;
reg [2:0] nanbei;
parameter start=4'b0000, //開始
first=4'b0001, //第1位
second=4'b0010,//第2位
third=4'b0011, //第3位
fourth=4'b0100, //第4位
fifth=4'b0101, //第5位
sixth=4'b0110, //第6位
seventh=4'b0111, //第7位
eighth=4'b1000; //第8位
reg [3:0] state;
reg [5:0] cnt;
always @ (posedge clk or negedge rst_n)
begin
if(!rst_n) begin
dongxi <= 0;
nanbei <= 0;
cnt <= 0;
state <= start;
endelse
begin
case (state)
start: begin // chu shi
dongxi <= 3'b111;
nanbei <= 3'b111;
state <= first;
endfirst: // dongxi lv 20s
if(cnt==20) begin
state <= second;
cnt <= 0;
endelse begin
cnt <= cnt + 1'b1;
dongxi <= 3'b001;
nanbei <= 3'b100;
state <= first;
endsecond: // dongxi huang 5s
if(cnt==5) begin
state <= third;
cnt <= 0;
endelse begin
cnt <= cnt + 1'b1;
dongxi <= 3'b010;
nanbei <= 3'b100;
state <= second;
endthird: // nanbei lv 20s
if(cnt==20) begin
state <= fourth;
cnt <= 0;
endelse begin
cnt <= cnt + 1'b1;
dongxi <= 3'b100;
nanbei <= 3'b001;
state <= third;
end
fourth: // nanbei huang 5s
if(cnt==5) begin
state <= first;
cnt <= 0;
endelse begin
cnt <= cnt + 1'b1;
dongxi <= 3'b100;
nanbei <= 3'b010;
state <= fourth;
end
endcase
endend
endmodule
測試激勵:
`timescale 1ns/1ps
////
//module traffic_tb;
reg clk;
reg rst_n;
wire dongxi;
wire nanbei;
traffic i1 (
.clk(clk),
.rst_n(rst_n),
.dongxi(dongxi),
.nanbei(nanbei)
);parameter period = 10;
initial
begin
forever #(period/2) clk = ~clk;
endinitial
begin
clk = 0;
rst_n = 0;
#20 rst_n = 1;
#100000
$stop;
endendmodule
基於verilog的交通燈程式
module traffic clk,sm bit,key,sm seg,en,rst,hold,light1,light2 input clk 定義時鐘引腳 input rst,en 定義復位和使能引腳 output 7 0 sm bit 定義數碼管位選引腳 output 7 0 sm seg 定...
ewb交通燈報告和檔案 基於EWB的交通燈設計
本文著眼於目前普遍應用在城市道路上的交通燈控制系統,從課程設計的題目要求出發,設計了乙個十字路口主次街道的交通燈控制電路。首先進行交通燈狀態變換的分析和交通燈總體框架的設計,接著提出了2種電路設計方案,通過優劣比較後選定了方案2。電源電路由555定時器產生1hz的脈衝訊號 根據交通燈的四種執行狀態依...
交通燈控制
問題描述,十字路,東西方向和南北方向燈,綠20s黃5s紅25s,倒計時顯示時間,另外,警車救護車等特殊狀態,都顯紅燈,且時間顯示不斷閃爍,通過之後,恢復原狀態。以下是我編寫的源 library ieee use ieee.std logic 1164.all use ieee.std logic u...