-- W programie zaimplementowany jest licznik synchroniczny mod 4 -- zrealizowany na dwoch przerzutnikach D. Sygnal zegarowy podawany -- jest z generatora o czestotliwosci 27MHz odpowiednio spowolnionego. -- Klawisz key(0) sluzy jako przycisk LOAD, ktory ustawia licznik -- w stan poczatkowy odpowiadajacy polozeniu przelacznikow sw(0) (bit -- mniej znaczacy) oraz sw(1) (bit bardziej znaczacy). Przerzutniki -- reaguja na zbocze narastajace zegara i na LOAD=0. Stan zegara -- wyswietlany jest na diodzie zielonej ledg(1), stan klawisza LOAD -- na ledg(0). Stan licznika wyswietlany jest na wyswietlaczu -- 7-segmentowym hex0, stan poczatkowy na wyswietlaczu hex4. library IEEE; -- dolaczenie standardowej biblioteki IEEE use IEEE.STD_LOGIC_1164.all; entity ex_load is -- glowny element projektu port ( clock_27: in std_logic; key: in std_logic_vector(0 to 0); sw: 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_load; architecture ar_clk of ex_load is signal s: std_logic_vector(0 to 1); signal clk: std_logic := '0'; signal i: integer := 0; component clock port( we: in std_logic; i: inout integer; wy: out std_logic ); end component; 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; pre: in std_logic; clr: in std_logic; wy: out std_logic ); end component; begin hex1 <= "1111111"; hex2 <= "1111111"; hex3 <= "1111111"; hex5 <= "1111111"; hex6 <= "1111111"; hex7 <= "1111111"; ledg(1) <= clk; ledg(0) <= key(0); i0: clock port map (clock_27, i, clk); i1: d port map (not s(0), clk, not key(0) and sw(0), not key(0) and not sw(0), s(0)); i2: d port map ((s(0) and not s(1)) or (not s(0) and s(1)), clk, not key(0) and sw(1), not key(0) and not sw(1), s(1)); i3: digit port map (s, hex0); i4: digit port map (sw(0 to 1), hex4); end ar_clk; library IEEE; use IEEE.STD_LOGIC_1164.all; entity clock is -- zmniejszenie czestotliwosci zegara systemowego port ( we: in std_logic; i: inout integer; wy: out std_logic ); end clock; architecture ar_cl of clock is begin process (we) begin if rising_edge(we) then i <= i+1; if i = 27000000 then wy <= '1'; end if; if i = 54000000 then i <= 0; wy <= '0'; end if; end if; end process; end ar_cl; 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; pre: in std_logic; clr: in std_logic; wy: out std_logic ); end d; architecture ar_d of d is begin process (clk,pre,clr) begin if pre='1' then wy <= '1'; elsif clr='1' then wy <= '0'; else if rising_edge(clk) then wy <= we; end if; end if; end process; end ar_d;