//----------------------Dzielnik częstotliwości--------------------------//
library ieee;
use ieee.std_logic_1164.all;
entity dzielnik is
port(
clk in st/d_logic;
c1,c2: out std_logic;
);
end dzielnik;
architecture behavioral of dzielnik is
begin
D0: process (clk) --Na wyjściu dla guzika chemy osiągnąć
mniejszą częstotliwość,1MHz
variable i: integer := 0;
begin
if clk'event and clk='1' then --kolejny obieg zegara
i := i + 1;
if i = 25175 then
c1 <= '0';
i := 0;
else if i > 12587.5
c1 <= '1';
else
c1 <= '0';
end if;
end if;
end process;
D1: process (clk) --Na wyjściu dla układu generującego
chemy osiągnąć mniejszą częstotliwość,3Hz
variable i: integer := 0;
begin
if clk'event and clk='1' then --kolejny obieg zegara
i := i + 1;
if i = 8391666 then
c2 <= '0';
i := 0;
else if i > 4195833
c2 <= '1';
else
c2 <= '0';
end if;
end if;
end process;
end behavioral;
//-----------------------Debauncer dla guzika eliminujący drganie styków-----------------//
library ieee;
use ieee.std_logic_1164.all;
entity debouncer is
port (
clk: in std_logic;
przycisk: in std_logic;
przycisk_deb: out std_logic
);
end debouncer;
architecture behavioral of debouncer is
signal shift: std_logic_vector(3 downto 0);
signal stan: std_logic := '0';
begin
debounce : process(clk, shift, stan)
begin
if rising_edge(clk) then
shift(2 downto 0) <= shift(3 downto 1);
shift(3) <= przycisk;
case shift is
when "0000" => stan <= '0';
when "1111" => stan <= '1';
when others => stan <= stan;
end case;
end if;
przycisk_deb <= state;
end process;
end behavioral;
//---------------Transkoder kodu binarnego na wyświetlacz siedmiosegmentowy----------------//
library ieee;
use ieee.std_logic_1164.all;
entity transkoder is
port(
wej: in std_logic_vector(2 downto 0);
wyj: out std_logic_vector(6 downto 0);
);
end transkoder;
architecture behavioral of transkoder is
begin
case wej is
when "001" => wyj <= "1001111"; --1
when "010" => wyj <= "0010010"; --2
when "011" => wyj <= "0000110"; --3
when "100" => wyj <= "1001100"; --4
when "101" => wyj <= "0100100"; --5
when "110" => wyj <= "0100100"; --6
end case;
end behavioral;
//----------------Przerzutnik typu T dla guzika(blokada cyfry na wyświetlaczu)-------------//
library ieee;
use ieee.std_logic_1164.all;
entity przerzutnik_t is
port(
clk: in std_logic;
t: in std_logic;
q: out std_logic;
);
end przerzutnik_t
architecture behavioral of przerzutnik_t is
begin
signal q_teraz: std_logic;
signal q_nast: std_logic;
P : process(clk)
begin
if clk'event and clk = '1'
q_teraz <= q_nast;
q_nast = q_teraz when t='0' else not(q_teraz);
q <= q_teraz;
end if;
end process;
end behavioral;
//-------------------------------------Licznik modulo 6-----------------------------------//
library ieee;
use ieee.std_logic_1164.all;
entity licznik_mod_6 is
port(
clk: in std_logic;
wyj: out std_logic_vector(2 downto 0);
);
end licznik_mod_6;
architecture behavioral of licznik_mod_6 is
begin
P : process(clk)
variable i: integer := 0;
begin
if clk'event and clk = '1' then
i := i + 1; --liczymy obiegi
if i = 7 then
i := 0;
end if;
case i is when 1 => wyj <= "001";
when 2 => wyj <= "010";
when 3 => wyj <= "011";
when 4 => wyj <= "100";
when 5 => wyj <= "101";
when 6 => wyj <= "110";
end case;
end if;
end process;
end behavioral;
//---------------------------------Zaprzeczenie-----------------------------------------------//
library ieee;
use ieee.std_logic_1164.all;
entity zaprzeczenie is
port(
wej: in std_logic;
wyj: out std_logic;
);
end zaprzeczenie;
architecture behavioral of zaprzeczenie is
begin
wyj <= not(wej);
end behavioral;