交通燈的設(shè)計(jì)與實(shí)現(xiàn)_第1頁
交通燈的設(shè)計(jì)與實(shí)現(xiàn)_第2頁
交通燈的設(shè)計(jì)與實(shí)現(xiàn)_第3頁
交通燈的設(shè)計(jì)與實(shí)現(xiàn)_第4頁
交通燈的設(shè)計(jì)與實(shí)現(xiàn)_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、一、設(shè)計(jì)任務(wù)設(shè)計(jì)一個十字路口的紅、綠、黃三色信號交通燈控制電路,具體要求如下: 1)用紅、綠、黃三色發(fā)光二極管作信號燈。主干道為東西向,有紅、綠、黃三個燈;另一支干道為南北向,也有紅、綠、黃三個燈。紅燈亮禁止通行;綠燈亮允許通行;黃燈亮則給行駛中的車輛有時間??康浇芯€之外。 2)東西和南北每次綠燈放行26s,紅燈禁止30s。 在每次由亮綠燈變成亮紅燈的轉(zhuǎn)換過程中間,需要亮5s的黃燈作為過渡,以使行駛中的車輛有時間??康浇芯€以外。 3)能實(shí)現(xiàn)正常的、即時顯示功能,用實(shí)驗(yàn)箱上的4個七段數(shù)碼管作為到計(jì)時顯示器,分別顯示東西、南北方向的紅燈、綠燈、黃燈時間。 二、設(shè)計(jì)原理首先要對時鐘進(jìn)行分頻。由于

2、系統(tǒng)時鐘頻率比較大,因此首先分頻產(chǎn)生時鐘,用于下面的電路的控制;然后是各種顏色之間的轉(zhuǎn)換,在此在添加一個使能端en,當(dāng)使能端en為1的時候,就開始進(jìn)行狀態(tài)循環(huán)以及倒計(jì)時,然后en就立即變?yōu)?;在狀態(tài)機(jī)中一共有四個狀態(tài),如下圖所示: 然后,我們這里用了BCD碼表示倒計(jì)時時間。燈亮或閃爍時間(綠、黃、紅分別為26s、130s、5s)用BCD碼表示(分別為26h、30h、5h),倒計(jì)時的時候個位和十位分別是BCD碼的高四位和低四位,首先是低四位倒數(shù),當(dāng)?shù)箶?shù)到0時,給它重新賦值為9,且高四位減1,如此循環(huán),直到這個數(shù)減到0,此時表示某一個燈亮的時間到,接著進(jìn)行下一個狀態(tài),為了能使進(jìn)入下一個狀態(tài), 必須

3、在時間減到0的時候,給使能端en 賦值1;由于用的BCD碼,高四位和低四位就分別是我們要在譯碼模塊的要用數(shù)碼管顯示的十位和個位。用數(shù)據(jù)選擇器來控制東西、南北的燈亮。三、程序流程圖 開始計(jì)數(shù)開始高電平個是否小于5M輸出進(jìn)行反向電平計(jì)數(shù)累加YN 11分頻器的設(shè)計(jì)流程圖 開始是否有清零信號個位是否為4計(jì)數(shù)開始繼續(xù)累加NYNY個位輸出0 1.2 5進(jìn)制的設(shè)計(jì)流程圖 開始是否有清零信號個位是否為9計(jì)數(shù)開始十位是否為2個位十位清零個位加一十位加一輸出NYNNYY 1.3 30進(jìn)制的設(shè)計(jì)流程圖 開始是否有清零信號個位是否為9計(jì)數(shù)開始十位是否為2個位加一十位加一輸出個位是否為5個位加一十位個位清零YNNNY

4、1.4 26進(jìn)制的設(shè)計(jì)流程圖甲道行駛,乙道禁止?fàn)顟B(tài)s0R1=0,G1=1,Y1=0R2=0,G2=0,Y2=0C2是否為1NY甲道停止,乙道禁止R1=0,G1=0,Y1=1R2=0,G2=0,Y2=0C1是否為1N狀態(tài)s1R1=1,G1=0,Y1=0R2=0,G2=1,Y2=0甲道禁止,乙道行駛狀態(tài)s2YC2是否為1甲道禁止,乙道停止Y狀態(tài)s3NC1是否為1NR1=1,G1=0,Y1=0R2=0,G2=0,Y2=1Y 1.5 狀態(tài)機(jī)的程序流程圖四、程序設(shè)計(jì)1、5進(jìn)制的設(shè)計(jì)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_un

5、signed.all;entity jinzhi5 isport(clk,en,rst:in std_logic; ge,shi: out std_logic_vector(3 downto 0); cout:out std_logic); end jinzhi5; architecture behav of jinzhi5 isbegin process(clk,en) variable a,b: std_logic_vector(3 downto 0);begin if(rst=0) then a:=0101;b:=0000 elsif clkevent and clk=1 then if

6、(en=1) then if(a=0) then a:=0101;b:=0000,cout=1; else a:=a-1;b:=0000,cout=0; end if; end if; end if; ge=a;shi=b; end process; end behav; 仿真結(jié)果2、 26進(jìn)制的程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jinzhi26 isport(clk,en:in std_logic; ge: out std_logic_vector(3 downt

7、o 0); shi: out std_logic_vector(3 downto 0); cout:out std_logic); end jinzhi26; architecture behav of jinzhi26 isbegin process(clk,en) variable a: std_logic_vector(3 downto 0); variable b: std_logic_vector(3 downto 0);begin if(en=0) then a:=0010;b:=0101; elsif clkevent and clk=1 then if(a=0 and b=0)

8、 then a:=0010;b:=0101;cout=1; else if(b=0) then b:=1001;a:=a-1; else b:=b-1;cout=0; end if; end if; end if; ge=b;shi=a; end process; end behav; 仿真結(jié)果3、30進(jìn)制的程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity jinzhi30 isport(clk,en,rst:in std_logic; ge: out std_logic_vect

9、or(3 downto 0); shi: out std_logic_vector(3 downto 0); cout:out std_logic); end jinzhi30; architecture behav of jinzhi30 isbegin process(clk,en) variable a: std_logic_vector(3 downto 0); variable b: std_logic_vector(3 downto 0);begin if(rst=0) then a:=0000;b:=0000; elsif clkevent and clk=1 then if e

10、n=1 then if(a=0 and b=0) then a:=0011;b:=0000;cout=1; else if(b=0) then b:=1001;a:=a-1; else b:=b-1;cout=0; end if; end if; end if; end if; ge=b;shi=a; end process; end behav; 仿真結(jié)果4、10M分頻器的設(shè)計(jì)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin20 isport(clk:in std_lo

11、gic; c:out std_logic); end fenpin10; architecture art of fenpin10 is signal m: std_logic_vector(31 downto 0); signal c1:std_logic; begin process(clk) begin if rising_edge(clk) then if m then m=m+1; else m0);c1=not c1; end if; end if; c q q q q q q q q q q null; end case; end process; qout=q; end beh

12、av; 仿真波形6、四選一數(shù)據(jù)分配器的程序 數(shù)據(jù)選擇器中,Y1,Y2,Y2是從狀態(tài)機(jī)中輸出的控制信號,sshi,sge分別代表30進(jìn)制的十位和各位,eshi,ege分別代表26進(jìn)制的十位和各位,wshi,wge分別代表5進(jìn)制的十位和各位。jshi,jge分別連接著甲道的數(shù)碼管來顯示時間。Yshi,yge分別連接著甲道的數(shù)碼管來顯示時間。由于仿真時候設(shè)置的數(shù)據(jù)太多了,在這里就不進(jìn)行波形仿真了。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity xuanzeqi isport(Y1,Y2,Y

13、3,rst:in std_logic; sshi,sge,eshi,ege,wu:in std_logic_vector(3 downto 0); jshi,jge,yshi,yge:out std_logic_vector(3 downto 0); end xuanzeqi; architecture behav of xuanzeqi is signal yy: std_logic_vector(2 downto 0);begin yy=Y1&Y2&Y3; process(yy)begin if rst=0 then jshi=0000;jge=0000;yshi=0000;yge jsh

14、i=eshi;jge=ege;yshi=sshi;yge jshi=0000;jge=wu;yshi=sshi;yge jshi=sshi;jge=sge;yshi=eshi;yge jshi=sshi;jge=sge;yshi=0000;ygenull; end case; end if; end process; end behav; 7、狀態(tài)機(jī)的設(shè)計(jì)w1,w2,w3分別為5、26、30進(jìn)制的進(jìn)位輸出信號,c1,c2,c3分別連接著5、26、30進(jìn)制的使能端,控制計(jì)數(shù)器輸出信號。Y1,g1,r1分別為甲道的黃燈、綠燈、紅燈。,y2,g2,r2分別為乙道的黃燈、綠燈、紅燈。Z0,z1,z2連

15、接數(shù)據(jù)選擇器輸入端,控制數(shù)據(jù)選擇器的輸出數(shù)碼管。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity zhuangtaiji is port(reset,clk:in std_logic; w1,w2,w3: in std_logic; c1,c2,c3:out std_logic; y1,y2:out std_logic; g1,g2:out std_logic; r1,r2:out std_logic; z0,z1,z2:out std_logic); end zhuangtaiji;

16、 architecture behv of zhuangtaiji is type fsm_st is (s0,s1,s2,s3); signal c_st,next_state: fsm_st; begin reg:process(reset,clk) begin if reset=0 then c_st=s0; elsif clk=1 and clkevent then c_stg1=1; g2=0;r1=0;r2=1;y1=0;y2=0; c3=1;c2=1;c1=0; z2=0;z1=0;z0=1; if w2=1 then next_state=s1; else next_state

17、g1=0; g2=0;r1=0;r2=1;y1=1;y2=0; c3=1;c2=0;c1=1; z2=0;z1=1;z0=0; if w1=1 and w3=1 then next_state=s2; else next_stateg1=0; g2=1;r1=1;r2=0;y1=0;y2=0; c3=1;c2=1;c1=0; z2=0;z1=1;z0=1; if w2=1 then next_state=s3; else next_stateg1=0; g2=0;r1=1;r2=0;y1=0;y2=1; c3=1;c2=0;c1=1; z2=1;z1=0;z0=0; if w1=1 and w3=1 then next_state=s0; else next_statenext_state=s0; end case; end process com; end behv; 狀態(tài)圖觀察頂層電路圖五、心得體會本次實(shí)驗(yàn)設(shè)計(jì)了一個簡單的十字路口的交通燈亮燈程序,電路關(guān)鍵是在進(jìn)行時序狀態(tài)轉(zhuǎn)換,倒計(jì)時計(jì)數(shù),譯碼模塊控制紅、綠、黃燈過程。其實(shí)經(jīng)過分析我們會發(fā)現(xiàn),在控制模塊和譯碼模塊都用到了一個分頻計(jì)數(shù)器和東西、南北的亮燈時間都可以使用同一個計(jì)數(shù)器。我們可以進(jìn)行優(yōu)化,在一個模塊里共用。 實(shí)驗(yàn)的內(nèi)容是這個學(xué)期所做的最系統(tǒng)的一個實(shí)驗(yàn),涉及到以前所做的單個模塊的

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論