紅綠燈控制電路VHDL20240608_RYG

 完成一個十字路口紅綠燈控制電路

https://youtube.com/shorts/F2PGvyhlvCQ

有RYG1與RYG2共兩組紅綠燈,紅綠燈的週期是10秒,綠燈4秒,黃燈1秒,紅燈5秒。

電源打開時起始狀態是RYG1亮綠燈,RGY2亮紅燈

設rst鈕,按下回到RYG1亮綠燈,RGY2亮紅燈繼續

LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8

LED1不使用
LED2=R1
LED3=Y1
LED4=G1
LED5不使用
LED6=R2
LED7=Y2
LED8=G2



library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

use ieee.std_logic_arith.all;

use ieee.numeric_std.all;

entity VHDL20240608_RYG is

port(

clk_4M:in std_logic;

rst:in std_logic;

RYG:out std_logic_vector(7 downto 0));

end VHDL20240608_RYG;

architecture aa of VHDL20240608_RYG is

signal cnt1:integer range 0 to 1999999:=0;

signal clk_sec:std_logic:='0';

signal cnt2:integer range 0 to 9:=0;

begin

process(clk_4M)

begin

if rising_edge(clk_4M) then

if cnt1=1999999 then

cnt1<=0;

clk_sec<=not clk_sec;

else

cnt1<=cnt1+1;

end if;

end if;

end process;

process(clk_sec)

begin

if rst='0' then

cnt2<=0;

elsif rising_edge(clk_sec) then

if cnt2=9 then

cnt2<=0;

else

cnt2<=cnt2+1;

end if;

end if;

end process;

RYG<= "00010100" when cnt2=0 else

"00010100" when cnt2=1 else

"00010100" when cnt2=2 else

"00010100" when cnt2=3 else

"00100100" when cnt2=4 else

"01000001" when cnt2=5 else

"01000001" when cnt2=6 else

"01000001" when cnt2=7 else

"01000001" when cnt2=8 else

"01000010" when cnt2=9 else

"00000000";

end aa;

留言

這個網誌中的熱門文章

量測例外練習01(計算+量測)

數位電子乙級02,鍵盤掃瞄裝置