📄 count.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity count is
port(ini,en,clk:in std_logic;
ar0,ag0,ay0,al0,br0,bg0,by0,bl0:out std_logic;
tah: buffer std_logic_vector(6 downto 4);
tal: buffer std_logic_vector(3 downto 0);
tbh: buffer std_logic_vector(6 downto 4);
tbl: buffer std_logic_vector(3 downto 0));
end count;
architecture behav of count is
signal light: std_logic_vector(7 downto 0);
signal ta: std_logic_vector(6 downto 0);
signal tb: std_logic_vector(6 downto 0);
signal s: std_logic_vector(2 downto 0);
constant artimeh : std_logic_vector(6 downto 4):="101";
constant artimel : std_logic_vector(3 downto 0):="0101";
constant agtimeh : std_logic_vector(6 downto 4):="100";
constant agtimel : std_logic_vector(3 downto 0):="0000";
constant altimeh : std_logic_vector(6 downto 4):="001";
constant altimel : std_logic_vector(3 downto 0):="0101";
constant abytimeh : std_logic_vector(6 downto 4):="000";
constant abytimel : std_logic_vector(3 downto 0):="0101";
constant brtimeh : std_logic_vector(6 downto 4):="110";
constant brtimel : std_logic_vector(3 downto 0):="0101";
constant bgtimeh : std_logic_vector(6 downto 4):="011";
constant bgtimel : std_logic_vector(3 downto 0):="0000";
constant bltimeh : std_logic_vector(6 downto 4):="001";
constant bltimel : std_logic_vector(3 downto 0):="0101";
begin
process(ini,en,clk,tah,tal,tbh,tbl)
begin
ta <=tah & tal;
tb <=tbh & tbl;
if ini='1' then
s<="000";
tah<="000";
tal(3)<='0';tal(2)<='0';
tal(1)<='0';tal(0)<='1';
tbh<="000";
tbl(3)<='0';tbl(2)<='0';
tbl(1)<='0';tbl(0)<='1';
elsif clk'event and clk='1'then
if en='1' then
tah<=tah; tal<=tal;
tbh<=tbh; tbl<=tbl;
else
if((ta=1)or(tb=1)) then
s<=s+1;
case s IS
when "000"=> tah<=agtimeh; tal<= agtimel; tbh<=brtimeh;tbl<=brtimel;
when "001"=> tah<=abytimeh; tal<= abytimel;
when "010"=> tah<=altimeh; tal<= altimel;
when "011"=> tah<=abytimeh; tal<= abytimel;
when "100"=> tah<=artimeh; tal<= artimel; tbh<=bgtimeh;tbl<=bgtimel;
when "101"=> tbh<=abytimeh; tbl<= abytimel;
when "110"=> tbh<=bltimeh; tbl<= bltimel;
when "111"=> tbh<=abytimeh; tbl<= abytimel;
when others=>null;
end case;
else s<=s;
end if;
if ta/=1 then
if tal=0 then
tal<="1001"; tah<=tah-1;
else tal<=tal-1;tah<=tah;
end if;
end if;
if tb/=1 then
if tbl=0 then
tbl<="1001"; tbh<=tbh-1;
else tbl <=tbl-1;tbh<=tbh;
end if;
end if;
end if;
end if;
end process;
light<="01001000"when s="001" else
"00101000"when s="010" else
"00011000"when s="011" else
"00101000"when s="100" else
"10000100"when s="101" else
"10000010"when s="110" else
"10000001"when s="111" else
"10000010"when s="000" else
"00000000";
ar0<=light(7);ag0<=light(6);ay0<=light(5);al0<=light(4);
br0<=light(3);bg0<=light(2);by0<=light(1);bl0<=light(0);
end behav;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -