library ieee;use ;use ;use ;entity top_traffic isport( clock : in std_logic;reset : in std_logic;chip1 : in std_logic;chip2 : in std_logic;seg_out : out std_logic_vector(6 downto 0);chip_sel : out std_logic;chip_sel1 : out std_logic;chip_sel2 : out std_logic;q_out : out std_logic_vector(11 downto 0));end ;architecture bhv of top_traffic iscomponent qhz_anyport( clk: in std_logic;Q: out std_logic);end component;component qhz_any1port( clk: in std_logic;Q: out std_logic);end component;component mux21aport( s : in std_logic;a,b : in std_logic_vector(6 downto 0);y : out std_logic_vector(6 downto 0));end component;component trafficport( clk : in std_logic;rst : in std_logic;times : out integer range 0 to 100;q : out std_logic_vector(11 downto 0);shi: out std_logic_vector(6 downto 0);ge: out std_logic_vector(6 downto 0));end component;signal m1 : std_logic;signal m2 : std_logic;signal m3 : integer range 0 to 100;signal m4 : std_logic_vector(6 downto 0);signal m5 : std_logic_vector(6 downto 0);beginu1 : qhz_any port map(clk=>clock,Q=>m1);u2 : qhz_any1 port map(clk=>clock,Q=>m2);u3 : qhz_any1 port map(clk=>clock,Q=>chip_sel);u4 : traffic port map(clk=>m1,times=>m3,q=>q_out,rst=>reset,ge=>m4,shi=>m5);u5 : mux21a port map(a=>m4,b=>m5,y=>seg_out,s=>m2);chip_sel1<=chip1;chip_sel2<=chip2;end bhv;-------------miao fenpin-----------library ieee;use ;use ;entity qhz_any isgeneric(n:integer:=20000000);port( clk: in std_logic;Q: out std_logic);end qhz_any;architecture bhv of qhz_any isbeginprocess(clk)variable cout:integer:=0;beginif clk'event and clk='1' thenif cout<(n/2) thenQ<='1'; cout:=cout+1;elsif cout<(n-1) thenQ<='0'; cout:=cout+1;else cout:=0;end if;end if;end process;end bhv;----------------scan fenpin-----------library ieee;use ;use ;entity qhz_any1 isgeneric(n:integer:=200000);port( clk: in std_logic;Q: out std_logic);end qhz_any1;architecture bhv of qhz_any1 isbeginprocess(clk)variable cout:integer:=0;beginif clk'event and clk='1' thenif cout<(n/2) thenQ<='1'; cout:=cout+1;elsif cout<(n-1) thenQ<='0'; cout:=cout+1;else cout:=0;end if;end if;end process;end bhv;--------------------traffic-------------library ieee;use ;use ;use ;entity traffic isport( clk : in std_logic;rst : in std_logic;times : out integer range 0 to 100;q : out std_logic_vector(11 downto 0);shi,ge:out std_logic_vector(6 downto 0));end traffic;architecture bhv of traffic issignal cnt : integer range 0 to 100;signal l1,l2:integer range 0 to 9;type state_value is (s1,s2,s3,s4);signal state : state_value;beginprocess(clk,rst)beginif rst='1' thenstate<=s1; --S,N travel E,W stopcnt<=39;q<="100001100001";elsif rising_edge(clk) thencase state iswhen s1=> --s1if cnt=0 thenstate<=s2;q<="100010100010";cnt<=4;elsestate<=s1;cnt<=cnt-1;end if;when s2=> --s2if cnt=0 thenstate<=s3;q<="001100001100";cnt<=44;elsestate<=s2;cnt<=cnt-1;end if;when s3=> --s3if cnt=0 thenstate<=s4;q<="010100010100";cnt<=4;elsestate<=s3;cnt<=cnt-1;end if;when s4=> --s4if cnt=0 thenstate<=s1;q<="100001100001";cnt<=39;elsestate<=s4;cnt<=cnt-1;end if;end case;end if;end process;l1<=cnt/10; l2<=cnt rem 10;---- JI SUAN SHI WEI ; GE WEIprocess(l1)begincase l1 is ------- XIAN SHI SHI WEIwhen 0=>shi<="1111110"; --0when 1=>shi<="0110000"; --1when 2=>shi<="1101101"; --2when 3=>shi<="1111001"; --3when 4=>shi<="0110011"; --4when 5=>shi<="1011011"; --5when 6=>shi<="1011111"; --6when 7=>shi<="1110000"; --7when 8=>shi<="1111111"; --8when 9=>shi<="1111011"; --9end case;end process;process(l2)begincase l2 is -------- XIAN SHI GE WEIwhen 0=>ge<="1111110"; --0when 1=>ge<="0110000"; --1when 2=>ge<="1101101"; --2when 3=>ge<="1111001"; --3when 4=>ge<="0110011"; --4when 5=>ge<="1011011"; --5when 6=>ge<="1011111"; --6when 7=>ge<="1110000"; --7when 8=>ge<="1111111"; --8when 9=>ge<="1111011"; --9end case;end process;end bhv;---------------------------2 xuan 1-----------library ieee;use ;entity mux21a isport( s : in std_logic;a,b : in std_logic_vector(6 downto 0);y : out std_logic_vector(6 downto 0));end mux21a;architecture one of mux21a isbeginprocess(a,b,s)beginif s='0' then y<=a; else y<=b;end if;end process;end one;~~自己用过的,时间根据你的改过了,11点就熄灯,没时间写特殊情况了,自己先看看哦