【正文】
039。139。039。 end if。039。 sign_state=110。139。139。139。139。 end if。 sign_state=101。139。 state=rewysn。) then recount=39。) then if (st_transfer=39。 and ena_scan=39。 elsif (a_m=39。 state=rewysn。 else recount=39。 state=gewrsn。) then recount=39。) then if (next_state=39。 and ena_1hz=39。 when rewysn= if (a_m=39。 end if。 state=rewysn。 else recount=39。139。039。139。039。 end if。039。 sign_state=011。139。139。139。139。139。elseif (clk39。 recount=39。) then state=rewgsn。process(clk,ena_1hz,reset)beginif (reset=39。 end if。 end if。 st_transfer=39。139。 elsif(rebn_ff=2) then rebn_ff:=rebn_ff1。 st_transfer=39。139。139。elsif (clk39。 st_transfer=39。139。139。beginprocess(reset,clk,ena_scan,st_butt)variable rebn_ff:std_logic_vector(5 downto 0)。signal st_transfer:std_logic。architecture bhv of hld4 istype sreg0_type is (rewgsn, rewysn, gewrsn, yewrsn, yewysn, yewgsn, gewysn, rewrsn)。 yellow:out std_logic_vector(1 downto 0))。 red:out std_logic_vector(1 downto 0)。 recount:out std_logic。 st_butt:in std_logic。 flash_1hz:in std_logic。 ena_scan:in std_logic。entity hld4 isport(reset:in std_logic。use 。系統(tǒng)輸出信號(hào): recount:產(chǎn)生重新計(jì)數(shù)的輸出使能控制信號(hào);sign_state:產(chǎn)生輸出狀態(tài)信號(hào);red:負(fù)責(zé)紅色信號(hào)燈的顯示;green:負(fù)責(zé)綠色信號(hào)燈的顯示;yellow:負(fù)責(zé)黃色信號(hào)燈的顯示。因此,hld4紅綠燈信號(hào)控制電路(見圖11)除了負(fù)責(zé)監(jiān)控路口紅綠燈之外,最主要的功能就是能夠利用開關(guān)來切換手動(dòng)與自動(dòng)的模式,讓交通警察能夠通過外部輸入的方式來控制紅綠燈交通信號(hào)系統(tǒng)的運(yùn)做。其對(duì)應(yīng)方式如下表所示: 表1:LED25位系統(tǒng)輸出信號(hào)發(fā)光二極管7組6組5組4組3組2組1組led(24 downto 0)000yxwvutsrqponmlkjihgfedcba 紅綠燈信號(hào)控制電路在紅綠燈交通信號(hào)系統(tǒng)中,大多數(shù)的情況是通過自動(dòng)控制的方式指揮交通。在程序編寫過程中運(yùn)用到了conv_integer()語句,它可以將t_ff所賦的值轉(zhuǎn)換成整數(shù)。end。 when t_ff=1 else 39。next_state=39。 end if。 when others=led(24 downto 0)=0000000000000000000000000。 when 23=led(24 downto 0)=1111111111111111111111110。 when 21=led(24 downto 0)=1111111111111111111111000。 when 19=led(24 downto 0)=1111111111111111111100000。 when 17=led(24 downto 0)=1111111111111111110000000。 when 15=led(24 downto 0)=1111111111111111000000000。 when 13=led(24 downto 0)=1111111111111100000000000。 when 11=led(24 downto 0)=1111111111110000000000000。 when 9=led(24 downto 0)=1111111111000000000000000。 when 7=led(24 downto 0)=1111111100000000000000000。 when 5=led(24 downto 0)=1111110000000000000000000。 when 3=led(24 downto 0)=1111000000000000000000000。 when 1=led(24 downto 0)=1100000000000000000000000。 end if。 else t_ff=t_ff1。139。139。139。elsif (clk39。) then t_ff=00000000。beginprocess(clk,reset)beginif (reset=39。end。 led:out std_logic_vector(24 downto 0)。 recount:in std_logic。 clk:in std_logic。use 。use 。 end case。 when 24=led(24 downto 0)=1111111111111111111111111。 when 3=led(24 downto 0)=1111000000000000000000000。 when 1=led(24 downto 0)=1100000000000000000000000。 end if。 當(dāng)reset=0,clk為上升沿觸發(fā),且ena_1hz為1時(shí),recount為0時(shí),t_ff減1。當(dāng)reset=0,clk為上升沿觸發(fā),且ena_1hz與recount為1時(shí),load將減1的數(shù)值賦給t_ff。139。139。139。elsif (clk39。 led=0000000000000000000000000。139。經(jīng)仿真后得到的時(shí)序圖(見圖10):圖10 倒計(jì)時(shí)控制電路時(shí)序圖由倒計(jì)時(shí)控制電路的時(shí)序圖(見圖10)可以看出,當(dāng)clk時(shí)鐘信號(hào)來臨后,在ena_1hz脈沖信號(hào)的同時(shí)激勵(lì)下,led會(huì)按照預(yù)先設(shè)置好的時(shí)間開始逐1遞減,進(jìn)行倒計(jì)時(shí)顯示。圖9 倒計(jì)時(shí)控制電路系統(tǒng)輸入信號(hào):clk:由外部信號(hào)發(fā)生器提供1kHz的時(shí)鐘信號(hào);reset:系統(tǒng)內(nèi)部自復(fù)位信號(hào);ena_1hz:接收由時(shí)鐘發(fā)生電路提供的1Hz的脈沖信號(hào);recount:重新計(jì)數(shù)的使能控制信號(hào);load:負(fù)責(zé)接收計(jì)數(shù)器所需要的計(jì)數(shù)數(shù)值。因此,如果采用發(fā)光二極管作為倒計(jì)時(shí)的顯示裝置就會(huì)使司機(jī)和行人一目了然,同樣也能夠起到很好的提示作用。如此循環(huán)下去,道路就會(huì)暢通無阻了。 倒計(jì)時(shí)控制電路通過日常生活中的觀察,我發(fā)現(xiàn)在一些交通路口已經(jīng)開始使用倒計(jì)時(shí)顯示器,它們的作用就是用來提示車輛行人目前還有多長時(shí)間信號(hào)燈會(huì)發(fā)生變化,這樣車輛行人就可以提前判斷是否有足夠的時(shí)間通過路口,進(jìn)而就可以避免很多意外事故的發(fā)生。例如程序中:when 000=load=conv_std_logic_vector(greenew_time,8)。當(dāng)外部信號(hào)發(fā)生器提供了1kHZ的時(shí)鐘信號(hào),并且重新計(jì)數(shù)信號(hào)(recount)為“1”時(shí),load信號(hào)就會(huì)按照預(yù)先設(shè)置的數(shù)值逐1遞減,直至減到零為止,當(dāng)下一個(gè)重新計(jì)數(shù)信號(hào)(recount)再次為“1”時(shí),會(huì)重復(fù)此過程。 end process。 end if。 when others=load=conv_std_logic_vector(yellowsn_time,8)。 when 100=load=conv_std_logic_vector(yellowew_time,8)。 when 010=load=conv_std_logic_vector(redsn_time,8)。) then case sign_state is when 000=load=conv_std_logic_vector(greensn_time,8)。 and recount=39。) then if (ena_scan=39。event and clk=39。 then load=00000000。beginprocess(reset,clk)begin if reset=39。constant yellowsn_time:integer:=5。constant greenew_time:integer:=25。architecture bhv of hld2 isconstant redew_time:integer:=15。 load:out std_logic_vector(7 downto 0))。 recount:in std_logic。 clk:in std_logic。use 。計(jì)數(shù)秒數(shù)選擇電路程序代碼library ieee。 when others=load=conv_std_logic_vector(yellowsn_time,8)。 when 101=load=conv_std_logic_vector(greenew_time,8)。 when 100=load=conv_std_logic_vector(yellowew_time,8)。 when 011=load=conv_std_logic_vector(redew_time,8)。 when 010=load=conv_std_logic_vector(redsn_time,8)。 when 001=load=conv_std_logic_vector(yellowsn_time,8)。) then case sign_state is when 000=load=conv_std_logic_vector(greensn_time,8)。 and recount=39。) then if (ena_scan=39。event and clk=39。 then load=00000000。beginprocess(reset,clk)begin if reset=39。constant greensn_time:integer:=25。constant yellowsn_time:integer:=5。constant redsn_time:integer:=15。constant greenew_time:integer:=25。constant yellowew_time:integer:=5。architecture bhv of hld2 isconstant redew_time:integer:=15。系統(tǒng)輸出信號(hào): load:負(fù)責(zé)產(chǎn)生計(jì)數(shù)器所需要的計(jì)數(shù)數(shù)值。因此,hld2計(jì)數(shù)秒數(shù)選擇電路(見圖7)最主要的功能就是負(fù)責(zé)輸出顯示器需要的數(shù)值(即倒數(shù)的秒數(shù)值),作為倒計(jì)時(shí)顯示器電路的計(jì)數(shù)秒數(shù)。end。ena_1hz=ena_one and ena_two and ena_s。 end if。 end if。039。 else clk_2hz_ff=clk_2hz_ff+1。139。 then if clk_2hz_ff=two_hz_val1 then clk_2hz_ff=0000000。) then if ena_s=39。event and clk=39。 clk_2hz_f