




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
PAGEPAGE1715.6交通燈控制器程序設(shè)計與仿真實驗1.實驗?zāi)康耐瓿山煌艨刂破鞯脑O(shè)計,掌握狀態(tài)機的使用。2.實驗原理在十字路口,每條道路各有一組紅,黃,綠和倒計時顯示器,用以指揮車輛和行人有序的通行。其中,紅燈亮表示該道路禁止通行;黃燈亮表示停車;綠燈亮表示可以通行;倒計時顯示器是用來顯示允許通行或是禁止通行的時間。根據(jù)交通燈的工作方式,設(shè)計的交通燈由兩組紅綠燈信號控制四組交通燈,其中處于同一個方向的交通燈共用一組紅綠燈信號。顯示順序為:方向一為黃燈、紅燈、綠燈,方向二為綠燈、黃燈,紅燈?!?’表示燈亮,‘0’表示燈熄。其中綠燈,黃燈,紅燈的持續(xù)時間分別為25秒,5秒,20秒。寄存器傳輸級(RTL,用基本的寄存器和門電路搭成的電路)電路圖如圖5.6.1所示,CLK為信號燈提供秒輸入信號;信號燈模塊實現(xiàn)交通燈控制的邏輯功能。圖5.6.1系統(tǒng)設(shè)計原理圖3.實驗內(nèi)容(1)完成信號燈模塊的設(shè)計,并仿真。(2)設(shè)計頂層文件,實現(xiàn)交通燈控制器的設(shè)計。(3)為頂層文件建立引腳配置文件,下載進(jìn)行硬件測試。4.程序設(shè)計與仿真(1)源程序①信號燈模塊corna(corna.vhd),信號燈模塊corna源程序如下:libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entitycornaisPort(clk:instd_logic;r:outstd_logic;g:outstd_logic;y:outstd_logic;timh:outstd_logic_vector(3downto0);timl:outstd_logic_vector(3downto0));endcorna;architectureBehavioralofcornaistypergyis(yellow,green,red);--初態(tài)為黃燈beginprocess(clk)variablea:std_logic:='0';variableth,tl:std_logic_vector(3downto0);--計數(shù)高低位variablestate:rgy;beginifclk'eventandclk='1'thencasestateis--狀態(tài)機開始 whengreen=>ifa='0'then th:="0010"; tl:="0100"; a:='1'; g<='1'; r<='0';else ifnot(th="0000"andtl="0001")then--if語句處理顯示時間 iftl="0000"then tl:="1001"; th:=th-1;else tl:=tl-1;endif;else th:="0000"; tl:="0000"; a:='0'; state:=yellow;endif;endif;whenred=>ifa='0'then th:="0001"; tl:="1001"; a:='1'; r<='1'; y<='0';else ifnot(th="0000"andtl="0001")then iftl="0000"then tl:="1001"; th:=th-1;else tl:=tl-1;endif;else th:="0000"; tl:="0000"; a:='0'; state:=green;endif;endif; whenyellow=>ifa='0'then th:="0000"; tl:="0100"; a:='1'; g<='0';--初始態(tài)的設(shè)置,黃燈亮,綠燈,紅燈熄。 y<='1'; r<='0';else ifnot(th="0000"andtl="0001")then iftl="0000"then tl:="1001"; th:=th-1;else tl:=tl-1;endif;else th:="0000"; tl:="0000"; a:='0'; state:=red;endif;endif;endcase;endif;timh<=th;timl<=tl;endprocess;endBehavioral;②信號燈模塊cornb(cornb.vhd),信號燈模塊cornb源程序如下,模塊cornb和模塊corna程序很相近,只是狀態(tài)的初態(tài)不同,這在仿真結(jié)果中可以看到。libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entitycornbisPort(clk:instd_logic;r:outstd_logic;g:outstd_logic;y:outstd_logic;timh:outstd_logic_vector(3downto0);timl:outstd_logic_vector(3downto0));endcornb;architectureBehavioralofcornbistypergyis(green,yellow,red);--初態(tài)為綠燈beginprocess(clk)variablea:std_logic:='0';variableth,tl:std_logic_vector(3downto0);variablestate:rgy;beginifclk'eventandclk='1'thencasestateis--狀態(tài)機開始 whengreen=>ifa='0'then th:="0010"; tl:="0100"; a:='1'; g<='1';--初始態(tài)設(shè)置,綠燈亮,紅燈,黃燈熄。 r<='0'; y<='0';else ifnot(th="0000"andtl="0001")then iftl="0000"then tl:="1001"; th:=th-1;else tl:=tl-1;endif;else th:="0000"; tl:="0000"; a:='0'; state:=yellow;endif;endif;whenred=>ifa='0'then th:="0001"; tl:="1001"; a:='1'; r<='1'; y<='0';else ifnot(th="0000"andtl="0001")then iftl="0000"then tl:="1001"; th:=th-1;else tl:=tl-1;endif;else th:="0000"; tl:="0000"; a:='0'; state:=green;endif;endif; whenyellow=>ifa='0'then th:="0000"; tl:="0100"; a:='1'; g<='0'; y<='1';else ifnot(th="0000"andtl="0001")then iftl="0000"then tl:="1001"; th:=th-1;else tl:=tl-1;endif;else th:="0000"; tl:="0000"; a:='0'; state:=red;endif;endif;endcase;endif;timh<=th;timl<=tl;endprocess;endBehavioral;③頂層文件模塊(traff_top..vhd)源程序如下;libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;entitytraff_topisPort(clk:instd_logic;--時鐘信號r1:outstd_logic;--第一組信號燈y1:outstd_logic; g1:outstd_logic; r2:outstd_logic;--第二組信號燈y2:outstd_logic;g2:outstd_logic; r3:outstd_logic;--第三組信號燈 y3:outstd_logic; g3:outstd_logic; r4:outstd_logic;--第四組信號燈 y4:outstd_logic; g4:outstd_logic;aout1,aout2:outstd_logic_vector(3downto0);--用于時間顯示bout1,bout2:outstd_logic_vector(3downto0));--用于時間顯示endtraff_top;architectureBehavioraloftraff_topiscomponentcorna--元件說明語句port(clk:instd_logic;r,g,y:outstd_logic;timh,timl:outstd_logic_vector(3downto0));endcomponent;componentcornbport(clk:instd_logic;r,g,y:outstd_logic;timh,timl:outstd_logic_vector(3downto0));endcomponent;signalq1,q2,q3,q4,q5,q6:std_logic;signala1,a2,b1,b2:std_logic_vector(3downto0);beginu1:cor
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- T-ZSA 232-2024 特種巡邏機器人通.用技術(shù)要求
- T-ZJHQ 0003-2024 高等學(xué)校生活垃圾分類工作規(guī)范
- 2025年度電子商務(wù)平臺數(shù)據(jù)分析與報告合同模板
- 二零二五年度解除婚約合同范本:婚約解除后的財產(chǎn)清算、債務(wù)處理及子女監(jiān)護(hù)協(xié)議
- 2025年度鋼板租賃與回收利用合同
- 二零二五年度金融機構(gòu)資金轉(zhuǎn)入風(fēng)險管理合同
- 2025年度智慧能源管理系統(tǒng)擔(dān)保人履約保證合同
- 二零二五年度企業(yè)綠色金融項目補貼協(xié)議
- 二零二五年度情人協(xié)議書:浪漫愛情生活規(guī)劃合同范本
- 石壕吏:歷史背景與社會問題分析教學(xué)教案
- 2025中鐵集裝箱運輸有限責(zé)任公司招聘46人(京外地區(qū)崗位)筆試參考題庫附帶答案詳解
- 中國農(nóng)業(yè)大學(xué)人文與發(fā)展學(xué)院管理服務(wù)崗位招聘筆試真題2023
- 2023-2024 中國滑雪產(chǎn)業(yè)白皮書
- 揭陽市基層診所醫(yī)療機構(gòu)衛(wèi)生院社區(qū)衛(wèi)生服務(wù)中心村衛(wèi)生室地址信息
- 晉中項目投決會報告
- 二年級下冊數(shù)學(xué)課件-1.3 分草莓 北師大版(共14張PPT)
- 2022年中小學(xué)心理健康教育指導(dǎo)綱要
- 中國紅十字會救護(hù)員培訓(xùn)理論考試試卷 (1)附答案
- 高架橋梁混凝土工程專項施工方案
- 銀行案件風(fēng)險排查實施細(xì)則
- 亞馬遜品牌授權(quán)書(英文模板)
評論
0/150
提交評論