-- W programie zaimplementowany jest licznik synchroniczny mod 4 -- zrealizowany na dwoch przerzutnikach D. Sygnal zegarowy podawany -- jest za pomoca klawisza key(0), reset za pomoca klawisza key(1). -- Przerzutniki reaguja na zbocze narastajace zegara i na reset=0. -- Stan klawiszy wyswietlany jest na diodach zielonych ledg(0) i ledg(1). -- Stan licznika wyswietlany jest na wyswietlaczu 7-segmentowym hex0. library IEEE; -- dolaczenie standardowej biblioteki IEEE use IEEE.STD_LOGIC_1164.all; entity ex_d is -- glowny element projektu port ( key: in std_logic_vector(0 to 1); ledg: out std_logic_vector(0 to 1); hex0: out std_logic_vector(0 to 6); hex1: out std_logic_vector(0 to 6); hex2: out std_logic_vector(0 to 6); hex3: out std_logic_vector(0 to 6); hex4: out std_logic_vector(0 to 6); hex5: out std_logic_vector(0 to 6); hex6: out std_logic_vector(0 to 6); hex7: out std_logic_vector(0 to 6) ); end ex_d; architecture ar_d of ex_d is signal s: std_logic_vector(0 to 1); component digit port( we: in std_logic_vector(0 to 1); wy: out std_logic_vector(0 to 6) ); end component; component d port( we: in std_logic; clk: in std_logic; res: in std_logic; wy: out std_logic ); end component; begin hex1 <= "1111111"; hex2 <= "1111111"; hex3 <= "1111111"; hex4 <= "1111111"; hex5 <= "1111111"; hex6 <= "1111111"; hex7 <= "1111111"; ledg(0 to 1) <= key(0 to 1); i1: d port map (not s(0), key(0), key(1), s(0)); i2: d port map ((s(0) and not s(1)) or (not s(0) and s(1)), key(0), key(1), s(1)); i3: digit port map (s, hex0); end ar_d; library IEEE; use IEEE.STD_LOGIC_1164.all; entity digit is -- translacja wektora binarnego na cyfre dziesietna port ( we: in std_logic_vector(0 to 1); wy: out std_logic_vector(0 to 6) ); end digit; architecture ar_di of digit is begin wy(0) <= we(0) and not we(1); wy(1) <= '0'; wy(2) <= not we(0) and we(1); wy(3) <= we(0) and not we(1); wy(4) <= we(0); wy(5) <= we(0) or we(1); wy(6) <= not we(1); end ar_di; library IEEE; use IEEE.STD_LOGIC_1164.all; entity d is -- przerzutnik D port ( we: in std_logic; clk: in std_logic; res: in std_logic; wy: out std_logic ); end d; architecture ar_d of d is begin process (clk,res) begin if res='0' then wy <= '0'; else if rising_edge(clk) then wy <= we; end if; end if; end process; end ar_d;