国产久操视频-国产久草视频-国产久热精品-国产久热香蕉在线观看-青青青青娱乐-青青青青在线成人视99

  • 方案介紹
  • 附件下載
  • 相關(guān)推薦
申請(qǐng)入駐 產(chǎn)業(yè)圖譜

Quartus交通燈控制器Verilog代碼遠(yuǎn)程云端平臺(tái)

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論

2-23121Z9533a51.doc

共1個(gè)文件

名稱:Quartus交通燈控制器Verilog代碼遠(yuǎn)程云端平臺(tái)

軟件:Quartus

語(yǔ)言:Verilog

代碼功能:

設(shè)計(jì)要求:

由一條主干道和一條支干道匯合成十字路口,在每個(gè)人口處設(shè)置紅,綠、黃,左拐允許。

四盞信號(hào)燈,紅燈亮禁止通行,綠燈亮允許迪行,黃燈亮則給行駛中的車輛有時(shí)間停在禁行線外,左拐燈亮允許車轉(zhuǎn)向左拐彎。

信號(hào)燈變換次序?yàn)?主支干道交替通行,主干行亮5s黃燈讓行駛中的車輛有時(shí)間停到共行線外,左拐應(yīng)行15,亮5s黃燈,支30s,亮5s黃燈,左拐放行15s,亮5黃訂、各計(jì)時(shí)電路為倒計(jì)時(shí)顯示。

FPGA代碼Verilog/VHDL代碼資源下載:www.hdlcode.com

本代碼已在遠(yuǎn)程云端平臺(tái)驗(yàn)證,遠(yuǎn)程云端平臺(tái)如下,其他遠(yuǎn)程云端平臺(tái)可以修改管腳適配:

遠(yuǎn)程平臺(tái)照片.png

演示視頻:

設(shè)計(jì)文檔:

1. 工程文件

2. 程序文件

3. 程序編譯

4. 管腳分配

5. 仿真圖

分頻模塊

控制模塊

顯示模塊

部分代碼展示:

//狀態(tài)機(jī)控制模塊
module?state_machine(
input?clk_1Hz,//1Hz
input?key,//復(fù)位
output?reg?main_red,//主干道紅燈
output?reg?main_green,//主干道綠燈
output?reg?main_yellow,//主干道黃燈
output?reg?main_left,//主干道左轉(zhuǎn)燈
output?reg?branch_red,//支干道紅燈
output?reg?branch_green,//支干道綠燈
output?reg?branch_yellow,//支干道黃燈
output?reg?branch_left,//支干道左轉(zhuǎn)燈
output?reg?[7:0]?main_cnt,//主路倒計(jì)時(shí)
output?reg?[7:0]?branch_cnt//支路倒計(jì)時(shí)
);
//狀態(tài)機(jī)控制模塊
reg?[3:0]?state=4'd0;
//定義5個(gè)狀態(tài)
parameter?S0=4'd0;
parameter?S1=4'd1;
parameter?S2=4'd2;
parameter?S3=4'd3;
parameter?S4=4'd4;
parameter?S5=4'd5;
parameter?S6=4'd6;
parameter?S7=4'd7;
parameter?S8=4'd8;
reg?[7:0]?count_S0=8'd0;//定義計(jì)數(shù)器
reg?[7:0]?count_S1=8'd0;//定義計(jì)數(shù)器
reg?[7:0]?count_S2=8'd0;//定義計(jì)數(shù)器
reg?[7:0]?count_S3=8'd0;//定義計(jì)數(shù)器
reg?[7:0]?count_S4=8'd0;//定義計(jì)數(shù)器
reg?[7:0]?count_S5=8'd0;//定義計(jì)數(shù)器
reg?[7:0]?count_S6=8'd0;//定義計(jì)數(shù)器
reg?[7:0]?count_S7=8'd0;//定義計(jì)數(shù)器
wire?[7:0]?main_red_time;//主干道紅燈
wire?[7:0]?main_green_time;//主干道綠燈
wire?[7:0]?main_yellow_time;//主干道黃燈
wire?[7:0]?main_left_time;//主干道左轉(zhuǎn)燈
wire?[7:0]?branch_red_time;//主干道紅燈
wire?[7:0]?branch_green_time;//主干道綠燈
wire?[7:0]?branch_yellow_time;//主干道黃燈
wire?[7:0]?branch_left_time;//主干道左轉(zhuǎn)燈
assign?main_red_time=8'd55;//主干道紅燈
assign?main_green_time=8'd40;//主干道綠燈
assign?main_yellow_time=8'd5;//主干道黃燈
assign?main_left_time=8'd15;//主干道左轉(zhuǎn)燈
assign?branch_red_time=8'd65;//支干道紅燈
assign?branch_green_time=8'd30;//支干道綠燈
assign?branch_yellow_time=8'd5;//支干道黃燈
assign?branch_left_time=8'd15;//支干道左轉(zhuǎn)燈
//狀態(tài)機(jī)控制
always@(posedge?clk_1Hz?or?posedge?key)
if(key==1)
state<=S8;//復(fù)位
else
case(state)
S8:
state<=S0;
S0://主干道綠燈
if(count_S0>=main_green_time-1)//40s
state<=S1;
else
state<=S0;
S1://主干道黃燈
if(count_S1>=main_yellow_time-1)//5s
state<=S2;
else
state<=S1;
S2://主干道左轉(zhuǎn)燈
if(count_S2>=main_left_time-1)//15s
state<=S3;
else
state<=S2;
S3://主干道黃燈
if(count_S3>=main_yellow_time-1)//5s
state<=S4;
else
state<=S3;
S4://支干道綠燈
if(count_S4>=branch_green_time-1)//30s
state<=S5;
else
state<=S4;
S5://支干道黃燈
if(count_S5>=branch_yellow_time-1)//5s
state<=S6;
else
state<=S5;
S6://支干道左轉(zhuǎn)燈
if(count_S6>=branch_left_time-1)//15s
state<=S7;
else
state<=S6;
S7://支干道黃燈
if(count_S7>=branch_yellow_time-1)//5s
state<=S0;
else
state<=S7;
default:;
endcase
//主干道綠燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S0)
count_S0<=count_S0+1;//計(jì)時(shí)
else
count_S0<=8'd0;
//主干道黃燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S1)
count_S1<=count_S1+1;//計(jì)時(shí)
else
count_S1<=8'd0;
//主干道左轉(zhuǎn)燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S2)
count_S2<=count_S2+1;//計(jì)時(shí)
else
count_S2<=8'd0;
//主干道黃燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S3)
count_S3<=count_S3+1;//計(jì)時(shí)
else
count_S3<=8'd0;
//支干道綠燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S4)
count_S4<=count_S4+1;//計(jì)時(shí)
else
count_S4<=8'd0;
//支干道黃燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S5)?
count_S5<=count_S5+1;//計(jì)時(shí)
else
count_S5<=8'd0;
//支干道左轉(zhuǎn)燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S6)
count_S6<=count_S6+1;//計(jì)時(shí)
else
count_S6<=8'd0;
//支干道黃燈計(jì)時(shí)
always@(posedge?clk_1Hz)
if(state==S7)
count_S7<=count_S7+1;//計(jì)時(shí)
else
count_S7<=8'd0;
//控制紅綠燈
always@(posedge?clk_1Hz)
case(state)
S0://主干道綠燈
begin
main_red<=0;
main_green<=1;
main_yellow<=0;
main_left<=0;
branch_red<=1;
branch_green<=0;
branch_yellow<=0;
branch_left<=0;
end
S1://主干道黃燈
begin
main_red<=0;
main_green<=0;
main_yellow<=1;
main_left<=0;
branch_red<=1;
branch_green<=0;
branch_yellow<=0;
branch_left<=0;
end
S2://主干道左轉(zhuǎn)燈
begin
main_red<=0;
main_green<=0;
main_yellow<=0;
main_left<=1;
branch_red<=1;
branch_green<=0;
branch_yellow<=0;
branch_left<=0;
end
S3://主干道黃燈
begin
main_red<=0;
main_green<=0;
main_yellow<=1;
main_left<=0;
branch_red<=1;
branch_green<=0;
branch_yellow<=0;
branch_left<=0;
end
S4://支干道綠燈
begin
main_red<=1;
main_green<=0;
main_yellow<=0;
main_left<=0;
branch_red<=0;
branch_green<=1;
branch_yellow<=0;
branch_left<=0;
end
S5://支干道黃燈
begin
main_red<=1;
main_green<=0;
main_yellow<=0;
main_left<=0;
branch_red<=0;
branch_green<=0;
branch_yellow<=1;
branch_left<=0;
end
S6://支干道左轉(zhuǎn)燈
begin
main_red<=1;
main_green<=0;
main_yellow<=0;
main_left<=0;
branch_red<=0;
branch_green<=0;
branch_yellow<=0;
branch_left<=1;
end
S7://支干道黃燈
begin
main_red<=1;
main_green<=0;
main_yellow<=0;
main_left<=0;
branch_red<=0;
branch_green<=0;
branch_yellow<=1;
branch_left<=0;
end
S8://復(fù)位
begin
main_red<=1;
main_green<=0;
main_yellow<=0;
main_left<=0;
branch_red<=1;
branch_green<=0;
branch_yellow<=0;
branch_left<=0;
end
default:;
endcase
//倒計(jì)時(shí)控制
always@(posedge?clk_1Hz)
if(state==S0)begin//主干道綠燈
main_cnt=main_green_time-count_S0;
branch_cnt=branch_red_time-count_S0;
end
else?if(state==S1)begin//主干道黃燈
main_cnt=main_yellow_time-count_S1;
branch_cnt=branch_red_time-(main_green_time+count_S1);
end
else?if(state==S2)begin//主干道左轉(zhuǎn)燈
main_cnt=main_left_time-count_S2;
branch_cnt=branch_red_time-(main_green_time+main_yellow_time+count_S2);
end
else?if(state==S3)begin//主干道黃燈
main_cnt=main_yellow_time-count_S3;
branch_cnt=branch_red_time-(main_green_time+main_yellow_time+main_left_time+count_S3);
end
else?if(state==S4)begin//支干道綠燈
branch_cnt=branch_green_time-count_S4;
main_cnt=main_red_time-count_S4;
end
else?if(state==S5)begin//支干道黃燈
branch_cnt=branch_yellow_time-count_S5;
main_cnt=main_red_time-(branch_green_time+count_S5);
end
else?if(state==S6)begin//支干道左轉(zhuǎn)燈
branch_cnt=branch_left_time-count_S6;
main_cnt=main_red_time-(branch_green_time+branch_yellow_time+count_S6);
end
else?if(state==S7)begin//支干道黃燈
branch_cnt=branch_yellow_time-count_S7;
main_cnt=main_red_time-(branch_green_time+branch_yellow_time+branch_left_time+count_S7);
end
else?begin
branch_cnt=8'd88;
main_cnt=8'd88;
end
endmodule

點(diǎn)擊鏈接獲取代碼文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=364

  • 2-23121Z9533a51.doc
    下載

相關(guān)推薦