vhdl紅綠燈實驗_第1頁
vhdl紅綠燈實驗_第2頁
vhdl紅綠燈實驗_第3頁
vhdl紅綠燈實驗_第4頁
vhdl紅綠燈實驗_第5頁
已閱讀5頁,還剩5頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、南北方向和東西方向的共六個顏色燈(紅、黃、綠)按給定延遲時間循環(huán)點亮。東西方向通行30秒,南北方向通行30秒。選用2個七段碼顯示時間,進行倒計時。當時間到后,進行紅黃綠燈顯示切換。交通燈控制器的4個狀態(tài)南北公路東西公路狀態(tài)0 25秒綠紅狀態(tài)1 5秒紅燈紅+黃狀態(tài)2 25秒紅綠狀態(tài)3 5秒紅+黃紅交通燈控制器的狀態(tài)轉換圖library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity traffic_signal_light is port (clk:instd_logic;clr:instd_logi

2、c;rst:instd_logic; dig_sel_n:out std_logic_vector(7 downto 0);ewsn : out std_logic_vector(5 downto 0);dat_out:out std_logic_vector(7 downto 0);useless : out std_logic_vector(5 downto 0);end entity traffic_signal_light;architecture bhv of traffic_signal_light istype states is (S0,S1,S2,S3);signal cur

3、rent_state,next_state : states := S0; signal dig0,dig1,dig2,dig3 : std_logic_vector(7 downto 0);signal digSelectAddress : integer range 0 to 3;-當前將要顯示數碼管的地址控制線; signal data1: integer range 40 downto 0 ; -data => 送顯示的時鐘數字信號;signal data2 : integer range 40 downto 0 ;signal clock_1s : std_logic;sign

4、al clock_5ms: std_logic;-數碼管的譯碼函數- - 形參 data :為要譯碼的數字,范圍為:09; - 返回值 ledSegment :為譯碼好的七段數碼管斷碼;function decode( data: integer range 0 to 9 )return std_logic_vector isvariable ledSegment: std_logic_vector(7 downto 0);beginCASE data ISWHEN 0 =>ledSegment := "11000000"- 0xC0;0 WHEN 1 =>le

5、dSegment := "11111001"- 0xf9;1WHEN 2 =>ledSegment := "10100100"- 0xa4;2WHEN 3 =>ledSegment := "10110000"- 0xb0 3WHEN 4 =>ledSegment := "10011001"- 0x99 4WHEN 5 =>ledSegment := "10010010"- 0x92;5WHEN 6 =>ledSegment := "10000010&quo

6、t;- ox82;6WHEN 7 =>ledSegment := "11111000"- 0xf8;7WHEN 8 =>ledSegment := "10000000"- 0x80;8WHEN 9 =>ledSegment := "10010000"- 0x90;9WHEN OTHERS =>null; END CASE; return ledSegment;end decode;-begin -architecture useless <= "111111"dig1 <= de

7、code(data1 /10 rem 10);dig0 <= decode(data1 rem 10 );dig3 <= decode(data2 /10 rem 10);dig2 <= decode(data2 rem 10 ); -狀態(tài)轉換-Change_state : process(current_state) begin case current_state is when S0 => ewsn <= "110011"-rgif(data1 = 1 ) then next_state <= S1 ;else next_state

8、 <= S0 ;end if ;when S1 => ewsn <= "101011"-ryif(data1 = 1 ) then next_state <= S2 ;else next_state <= S1 ;end if ;when S2 => ewsn <= "011110"if( data1 = 5 ) then next_state <= S3 ;else next_state <= S2 ;end if ;when S3 => ewsn <= "011101&quo

9、t;if( data1 = 1 ) then next_state <= S0 ;else next_state <= S3 ;end if ;end case ;end process Change_state;-時序進程-Reg : process(clock_1s,rst)beginif rst = '1' then current_state <= S0;elsif (clock_1s = '1' and clock_1s'event) thencurrent_state <= next_state;end if; end

10、 process Reg; -分頻器輸出1s時鐘給數碼管的定時器-Div_clock_1s : process(clk) variable count :integer range 0 to 20_000_000 ;beginif(clk = '1' and clk'event) thenif count = 19_999_999 thencount:= 0;elsecount:= count +1;end if;if(count>= 10_000_000) thenclock_1s <= '0'elseclock_1s <= '

11、;1'end if;end if; end process Div_clock_1s; -25秒和5秒倒計時- -東西紅路燈數碼管倒計時- counter1 : process(clock_1s) variable data_60second : integer range 60 downto 1 ; begin if(clock_1s'event and clock_1s = '1')thenif( data1 = 0 ) thendata_60second := 60;data1 <= 25;else data_60second := data_60s

12、econd - 1; if( data_60second > 35 ) thendata1 <= ( data_60second - 35 ) ;else if(data_60second > 30) thendata1 <= (data_60second - 30 ) ;elsedata1 <= data_60second;end if;end if;end if;end if;end process counter1; -南北紅路燈數碼管倒計時- counter2 : process(clock_1s) variable data_60second : int

13、eger range 60 downto 1 ; begin if(clock_1s'event and clock_1s = '1')thenif( data2 = 0 ) thendata_60second := 60;data2 <= 30;else data_60second := data_60second - 1;if( data_60second > 30 ) thendata2 <= ( data_60second - 30 ) ;else if(data_60second > 5) thendata2 <= (data_6

14、0second - 5 ) ;else data2 <= data_60second;end if; end if;end if;end if;end process counter2; -數碼管刷新頻率產生進程-Div_clock_5ms : process(clk) variable count :integer range 0 to 100_000 ;beginif(clk = '1' and clk'event) thenif count = 99_999 thencount:= 0;elsecount:= count +1;end if;if(count

15、>= 50_000) thenclock_5ms <= '0'elseclock_5ms <= '1'end if;end if; end process Div_clock_5ms;-counter3 : process(clock_5ms) beginif(clock_5ms = '1' and clock_5ms'event) thenif digSelectAddress = 3 thendigSelectAddress <= 0;elsedigSelectAddress <= digSelectAddress + 1;end if;end if; end process counter3;- show : process(digSelectAddress) begincase digSelectAddress iswhen 0 => dig_sel_n <= "11111110"dat_out <= dig0;w

溫馨提示

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

評論

0/150

提交評論