【文章內(nèi)容簡(jiǎn)介】
nce issignal temp1,temp2: std_logic。begin process(key,clk) begin if clk39。event and clk=39。039。 then 與時(shí)鐘信號(hào)同步,并且 temp2=temp1。 與存儲(chǔ)先前值 temp1=key。 end if。 end process。 key_out=temp1 and (not temp2) and clk。 消抖輸出end。 Frequency1模塊Frequency1模塊,由于外部時(shí)鐘信號(hào)clk的頻率為1MHz,而實(shí)際需要的內(nèi)部計(jì)時(shí)時(shí)鐘頻率為1Hz,需要一個(gè)分頻電路。輸入端口:clk外部時(shí)鐘信號(hào)輸出端口:clk_out分頻后信號(hào)library ieee。use 。use 。entity Frequency1 is port( clk:in std_logic。 外部時(shí)鐘信號(hào) clk_out:out std_logic 分頻后信號(hào) )。end Frequency1。architecture Frequency1_arc of Frequency1 isbegin process(clk) variable temp:integer range 0 to 999999。 begin if(clk39。event and clk=39。139。)then if(temp=999999)then 分頻計(jì)數(shù) temp:=0。 clk_out=39。039。 else temp:=temp+1。 clk_out=39。139。 end if。 end if。 end process。 end。 .4 StatusSelect模塊StatusSelect模塊,由于共需要顯示4個(gè)數(shù)字,需要循環(huán)點(diǎn)亮7位數(shù)碼管,該模塊通過(guò)輸入的時(shí)鐘信號(hào),循環(huán)輸出4個(gè)選擇信號(hào)。當(dāng)緊急狀態(tài)信號(hào)到來(lái),改變顯示狀態(tài),通過(guò)計(jì)數(shù)部分,實(shí)現(xiàn)閃爍,并輸出蜂鳴信號(hào)。輸入端口:clk時(shí)鐘信號(hào),show緊急顯示輸出端口:sel選擇信號(hào),voice蜂鳴信號(hào)library ieee。use 。entity StatusSelect is port( clk,show:in std_logic。 時(shí)鐘信號(hào),緊急顯示 sel:out std_logic_vector(2 downto 0)。 選擇信號(hào) voice:out std_logic 蜂鳴信號(hào) )。end StatusSelect。architecture StatusSelect_arc of StatusSelect issignal temp:std_logic_vector(2 downto 0)。begin process(clk,show) variable t:integer range 0 to 499999。 variable a:std_logic。 begin if(clk39。event and clk=39。139。)then case show is when 39。039。 = 非緊急狀態(tài) voice=39。039。 case temp is when 000=temp=001。 when 001=temp=010。 when 010=temp=011。 when 011=temp=000。 when others=temp=000。 end case。 when others = 緊急狀態(tài) voice=a。 if(t=499999)then 閃爍計(jì)數(shù) t:=0。 a:=not a。 else t:=t+1。 end if。 if (a=39。139。) then case temp is when 000=temp=001。 when 001=temp=010。 when 010=temp=011。 when 011=temp=000。 when others=temp=000。 end case。 else temp=111。 end if。 end case。 end if。 sel=temp。 end process。end 。 TimeSelect模塊TimeSelect模塊,接收狀態(tài)選擇信號(hào)以及交通燈剩余時(shí)間信號(hào),根據(jù)狀態(tài)選擇信號(hào),選擇剩余時(shí)間的位數(shù)輸出給譯碼模塊,并選擇陰極控制顯示位置。輸入接口:sel狀態(tài)選擇信號(hào), timeh1 timel1 timeh2 timel2剩余時(shí)間輸出接口:catn共陰極控制,time_out數(shù)字輸出library ieee。use 。entity TimeSelect is port( sel:in std_logic_vector(2 downto 0)。 狀態(tài)選擇信號(hào) timeh1,timeh2,timel1,timel2:in std_logic_vector(3 downto 0)。 剩余時(shí)間 catn:out std_logic_vector(5 downto 0)。 共陰極控制 time_out:out std_logic_vector(3 downto 0) 數(shù)字輸出 )。end TimeSelect。architecture TimeSelect_arc of TimeSelect isbegin process(sel) begin case sel is 通過(guò)狀態(tài)信號(hào)選擇輸出 when 000=time_out=timeh1。 catn=111110。 when 001=time_out=timel1。 catn=111101。 when 010=time_out=timeh2。 catn=101111。 when 011=time_out=timel2。 catn=011111。 when others=time_out=0000。 catn=111111。 end case。 end p