目錄
題目要求
設(shè)計方法
部分程序設(shè)計
題目要求
(1) 以車為主體,綠燈、黃燈、紅燈、綠燈依次點亮;
(2)十字路口,具有兩組紅綠燈;
(3)采用倒計時顯示剩余時間,數(shù)碼管動態(tài)顯示;
(4)紅綠燈時間按鍵可調(diào)。
設(shè)計方法
用六位數(shù)碼管顯示,靠左和靠右兩位數(shù)碼管分別顯示東西和南北方向的倒計時顯示,我開發(fā)板剛好6個LED燈,但是是豎著的,上面三位表示南北方向的紅黃綠燈,下面三位表示東西方向的紅黃綠燈。平面圖如下:
首先需要一個1hz頻率進行倒計時計數(shù),然后對倒計時在不同時間段做出不同的判斷即可,為了方便理解,我畫出流程圖如下:(需要注意的是紅燈亮的時間應(yīng)該是黃燈和綠燈時間之和)
部分程序設(shè)計
module traffic(
input clk,
input rstn,
input [6:0]d2,//綠燈點亮?xí)r間
output reg [3:0] data1,
output reg [3:0] data2,
output reg [3:0] data5,
output reg [3:0] data6,
output reg [5:0] led
);
wire [6:0]d3; //紅燈點亮?xí)r間
assign d3=d2+5;
//1hz生成
reg [26:0]cn1;
reg clk1hz;
always@(posedge clk or negedge rstn)
begin
if(!rstn)
begin
cn1<=0;
clk1hz<=0;
end
else if(cn1>=24_999_999)//1hz頻率生成
begin
clk1hz<=!clk1hz;
cn1<=0;
end
else
cn1<=cn1+1;
end
//計數(shù)
reg [6:0]count;
always@(posedge clk1hz or negedge rstn)
begin
if(!rstn)
count<=0;
else if(count>=(d3+d3))//紅燈時間d3,加上黃燈和綠燈時間d3
count<=0;
else
count<=count+1;
end
//南北方向顯示
reg [6:0]north_red,north_green,north_yellow;
always@(posedge clk1hz or negedge rstn)
begin
if(!rstn)
begin
north_red<=0;
north_green<=0;
north_yellow<=0;
led[2:0]<=0;
data1<=0;
data2<=0;
end
else if(count<=d3)//南北方向紅燈點亮
begin
north_red<=d3-count;
led[2:0]<=3'b110;
data1<=north_red%10;//取時間低位
data2<=north_red/10;//取時間高位
end
else if((count>d3)&&(count<=(d3+d3-5)))//南北方向綠燈點亮
begin
north_green<=d3+d3-5-count;
led[2:0]<=3'b011;
data1<=north_green%10;
data2<=north_green/10;
end
else
begin
north_yellow<=d3+d3-count;//南北方向黃燈點亮
led[2:0]<=3'b101;
data1<=north_yellow%10;
data2<=north_yellow/10;
end
end
//東西方向顯示
reg [6:0]east_red,east_green,east_yellow;
always@(posedge clk1hz or negedge rstn)
begin
if(!rstn)
begin
east_red<=0;
east_green<=0;
east_yellow<=0;
led[5:3]<=0;
data5<=0;
data6<=0;
end
else if(count<=d3-5)
begin
east_green<=d3-5-count;
led[5:3]<=3'b011;
data5<=east_green%10;
data6<=east_green/10;
end
else if((count>=(d3-5))&&(count<=d3))
begin
east_yellow<=d3-count;
led[5:3]<=3'b101;
data5<=east_yellow%10;
data6<=east_yellow/10;
end
else
begin
east_red<=d3+d3-count;
led[5:3]<=3'b110;
data5<=east_red%10;
data6<=east_red/10;
end
end
endmodule
? ?
工程.v文件https://download.csdn.net/download/m0_59487432/85684464?spm=1001.2014.3001.5503文章來源:http://www.zghlxwxcb.cn/news/detail-509491.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-509491.html
到了這里,關(guān)于基于FPGA的交通燈電路設(shè)計(含程序)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!