問題描述,十字路,東西方向和南北方向燈,綠20s黃5s紅25s,倒計時顯示時間,另外,警車救護車等特殊狀態,都顯紅燈,且時間顯示不斷閃爍,通過之後,恢復原狀態。
以下是我編寫的源**:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity traffic_light is
port(clk,special:in std_logic;
timel_show1:buffer std_logic_vector(3 downto 0);--東西計數器低四位
timeh_show1:buffer std_logic_vector(3 downto 0);--東西計數器高四位
timel_show2:buffer std_logic_vector(3 downto 0);--南北計數器低四位
timeh_show2:buffer std_logic_vector(3 downto 0);--南北計數器高四位
light1:buffer std_logic_vector(2 downto 0);--東西方向燈
light2:buffer std_logic_vector(2 downto 0);--南北方向燈
);end entity traffic_light;
architecture behv of traffic_light is
signal timel,timeh:std_logic_vector(3 downto 0);
begin
light1<="100";--東西綠
light2<="001";--南北黃
timel<="0000";
timeh<="0101";
if special='0' then
if clk'event and clk='1' then
l1:loop
if timel<="0000" then
timeh<=timeh-1;
timel<="1001";
timel<=timel-1;
if timel<="0000" then
timeh<=timeh-1;
if timel="0000" and timeh="0000" then
timel<="0000";
timeh<="0010";
end if;
end if;
end if;
exit l1 when special='1';
end loop l1;
end if;
end if;
process(timel,timeh,clk,special)
begin
case timel and timeh is
when timel="0000" and timeh="0101" => light1<="100"
light2<="001";
if clk'event and clk='1' and special='1' then
timel_show1<="0000";
timeh_show1<="0010";--綠20s
timel_show1<="0101";
timeh_show1<="0010";--紅25s
if timel_show1="0000" then
timeh_show1<=timeh_show1-1;
timel_show1<="1001";
timel_show1<=timel_show1-1;
if timel_show1="0000" then
timeh_show1<=timeh_show1-1;
end if;
end if;
if timel_show2="0000" then
timeh_show2<=timeh_show2-1;
timel_show2<="1001";
timel_show2<=timel_show2-1;
if timel_show2="0000" then
timeh_show2<=timeh_show2-1;
end if;
end if;
if special='0' then
light1<="001";
light2<="001";
l2:loop
timel_show1<=timel_show1;
timeh_show1<=timeh_show1;
timel_show2<=timel_show2;
timeh_show2<=timeh_show2;
exit l2 when special='0';
end loop l2;
end if;
end if;
when timel="0000" and timeh="0011" => light1<="010"
light2<="001";
if clk'event and clk='1' and special='1' then
timel_show1<="0101";
timeh_show1<="0000";--黃5s
timel_show2<="0101";
timeh_show2<="0000";--紅5s
timel_show1<=timel_show1-1;
timel_show2<=timel_show2-1;
if special='0' then
light1<="001";
light2<="001";
l3:loop
timel_show1<=timel_show1;
timeh_show1<=timeh_show1;
timel_show2<=timel_show2;
timeh_show2<=timeh_show2;
exit l3 when special='0';
end loop l3;
end if;
end if;
when timel="0101" and timeh="0010" => light1<="001"
light2<="010";
if clk'event and clk='1' and special='1' then
timel_show1<="0101";
timeh_show1<="0010";--紅5s
timel_show2<="0101";
timeh_show2<="0000";--黃5s
timel_show1<=timel_show1-1;
timel_show2<=timel_show2-1;
if special='0' then
light1<="001";
light2<="001";
l4:loop
timel_show1<=timel_show1;
timeh_show1<=timeh_show1;
timel_show2<=timel_show2;
timeh_show2<=timeh_show2;
exit l4 when special='0';
end loop l4;
end if;
end if;
when timel="0000" and timeh="0010" => light1<="001"
light2<="100";
if clk'event and clk='1' and special='1' then
timel_show1<="0000";
timeh_show1<="0010";--紅20s
timel_show2<="0000";
timeh_show2<="0010";--綠20s
if timel_show1="0000" then
timeh_show1<=timeh_show1-1;
timel_show1<="1001";
timel_show1<=timel_show1-1;
if timel_show1="0000" then
timeh_show1<=timeh_show1-1;
end if;
end if;
if timel_show2="0000" then
timeh_show2<=timeh_show2-1;
timel_show2<="1001";
timel_show2<=timel_show2-1;
if timel_show2="0000" then
timeh_show2<=timeh_show2-1;
end if;
end if;
if special='0' then
light1<="001";
light2<="001";
l5:loop
timel_show1<=timel_show1;
timeh_show1<=timeh_show1;
timel_show2<=timel_show2;
timeh_show2<=timeh_show2;
exit l5 when special='0';
end loop l5;
end if;
end if;
end case;
end process;
end behv;
總結:除錯有錯誤,待修正,希望能和大家多交流。
eda交通燈控制器波形輸入 EDA交通燈控制器設計
很高 實驗五十字路 通燈控制器設計 一 實驗目的 進一步加強經典狀態機的設計 學會設計模可變倒計時計數器 二 實驗要求 一條主幹道,一條鄉間公路。組成十字路口,要求優先保證主幹道通行。有 mr 主紅 my 主黃 mg 主綠 cr 鄉紅 cy 鄉黃 cg 鄉綠 六盞交 通燈需要控制 交通燈由綠 紅有 ...
智慧型交通燈
交通燈有很多種型別,下面這個,還是比較簡單的。東西 a 南北 b 兩幹道交於乙個十字路口,各幹道有一組紅 黃 綠三色的指示燈,要求用微控制器控制交通燈,實現以下功能 1 a 道和b道上均有車輛要求通過時,a b道輪流放行。a道放行5分鐘 除錯時改為5秒鐘 b道放行4分鐘 除錯時改為4秒鐘 4 綠燈轉...
交通燈控制電路設計
交通燈控制電路設計 一 實驗目的 1 掌握一般狀態機的設計與應用。2 掌握交通燈的亮滅規律和控制器的工作原理。3 進一步熟悉 vhdl 語言程式設計,了解實際設計中的優化方案。二 實驗內容 1 實驗前完成交通燈控制電路程式的編寫。內容是設計乙個簡單的交通燈控制器,交通燈顯示用實驗箱的交通燈模組來顯示...