【文章內(nèi)容簡(jiǎn)介】
ect 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 is signal temp:std_logic_vector(2 downto 0)。 begin process(clk,show) variable t:integer range 0 to 499999。 11 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。 12 else temp=111。 end if。 end case。 end if。 sel=temp。 end process。 end 。 時(shí)間選擇 模塊( TimeSelect)的設(shè)計(jì) 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 is begin process(sel) begin 通過(guò)狀態(tài)信號(hào)選擇輸出 13 case sel is when 000=time_out=timeh1。 catn=111110。 點(diǎn)亮第一個(gè)數(shù)碼管 when 001=time_out=timel1。 catn=111101。 點(diǎn)亮第二個(gè)數(shù)碼管 when 010=time_out=timeh2。 catn=101111。 點(diǎn)亮第五個(gè)數(shù)碼管 when 011=time_out=timel2。 catn=011111。 點(diǎn)亮第六個(gè)數(shù)碼管 when others=time_out=0000。 catn=111111。 否則都不點(diǎn)亮 end case。 end process。 end。 譯碼顯示模塊( Display)的設(shè)計(jì) Display 模塊,接收數(shù)字信號(hào),進(jìn)行 7位數(shù)碼管顯示譯碼輸出。 輸入接口: num_in 輸入信號(hào) 輸出接口: num_out 譯碼輸出 library ieee。 use 。 entity Display is port( num_in:in std_logic_vector(3 downto 0)。 實(shí)際數(shù)值 num_out:out std_logic_vector(6 downto 0) 譯碼輸出 )。 end Display。 architecture Display_arc of Display is begin process(num_in) 14 begin 譯碼 case num_in is when 0000=num_out=0111111。 0 when 0001=num_out=0000110。 1 when 0010=num_out=1011011。 2 when 0011=num_out=1001111。 3 when 0100=num_out=1100110。 4 when 0101=num_out=1101101。 5 when 0110=num_out=1111101。 6 when 0111=num_out=0100111。 7 when 1000=num_out=1111111。 8 when 1001=num_out=1101111。 9 when others=num_out=0000000。 非 8432BCD 碼 end case。 end process。 end。 信號(hào)燈控制模塊的設(shè)計(jì) 信號(hào)燈控制模塊,東西方向 ControlA,南北方向 ControlB。自定義一個(gè) Type類型,包括 green,yellow,red,turn 狀態(tài),接收到分頻后的信號(hào),通過(guò) case 語(yǔ)句,進(jìn)行狀態(tài)選擇,在每個(gè)狀態(tài)下分別計(jì)時(shí),當(dāng)計(jì)時(shí)結(jié)束后,選擇下一個(gè)狀態(tài),循環(huán)顯示。當(dāng)緊急狀態(tài)下,停止循環(huán),計(jì)數(shù)停止。 輸入接口: clk時(shí)鐘信號(hào), show 緊急狀態(tài)控制 輸出接口: timeh timel 計(jì)時(shí)數(shù)字輸出, r g y t 信號(hào)燈輸出 (ControlA 和 ControlB 大體相同, A 中“ variable temp_color:color:=green”一句中, temp_color 賦值 green, B中賦值 red,故省略 ) library ieee。 use 。 use 。 entity ControlA is port( 15 clk:in std_logic。 時(shí)鐘信號(hào) show:in std_logic:=39。139。 緊急狀態(tài) timeh,timel:out std_logic_vector(3 downto 0)。 計(jì)時(shí)數(shù)字輸出 r,g,y,t:out std_logic 信號(hào)燈輸出 )。 end ControlA。 architecture ControlA_arc of ControlA is type color is(green,yellow,red,turn)。 begin process(clk,show) variable reset:std_logic:=39。039。 variable tempr,tempg,tempy,tempt:std_logic。 variable temp_h,temp_l:std_logic_vector(3 downto 0)。 variable temp_color:color:=green。 begin if(clk39。event and clk=39。139。)then case show is when 39。039。= 非緊急狀態(tài) case temp_color is when yellow= 黃燈 亮 tempr:=39。039。 tempg:=39。039。 tempy:=39。139。 tempt:=39。039。 case reset is 計(jì)時(shí)部分 when 39。039。 = 歸零 temp_h:=0000。 temp_l:=0100。 reset:=39。139。 16 when others = 計(jì)時(shí) case temp_l is when 0000= temp_l:=1001。 temp_h:=temp_h1。 when 0001= case temp_h is when 0000 = temp_h:=0000。 temp_l:=0000。 reset:=39。039。 temp_color:=red。 when others = temp_l:=0000。 end case。 when others= temp_l:=temp_l1。 end case。 end case。 when green= 綠燈 亮 tempr:=39。039。 tempg:=39。139。 tempy:=39。039。 tempt:=39。039。 case reset is 計(jì)時(shí)部分 when 39。039。 = 歸零 temp_h:=0000。 temp_l:=1001。 reset:=39。139。 17 when others = 計(jì)時(shí) case temp_l is when 0000= temp_l:=1001。 temp_h:=temp_h1。 when 0001= case temp_h is when 0000 = temp_h:=0000。 temp_l:=0000。 reset:=39。039。 temp_color:=turn。 when others = temp_l:=0000。 end case。 when others= temp_l:=temp_l1。 end case。 end case。 when red= 紅燈 亮 tempr:=39。139。 tempg:=39。039。 tempy:=39。039。 tempt:=39。039。 case reset is 計(jì)時(shí)部分 when 39。039。 = 歸零 temp_h:=0010。 temp_l:=0100。 reset:=39。139。 18 when others = 計(jì)時(shí) case temp_l is when 0000= temp_l:=1001。 temp_h:=temp_h1。 when 0001= case temp_h is when 0000 = temp_h:=0000。 temp_l:=0000。 reset:=39。039。 temp_c