library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;
entity counter is
port
(
clk, set, rst : in std_logic;
count : out std_logic_vector (7 downto 0)
);
end counter;
architecture behave of counter is
signal cnt: std_logic_vector (7 downto 0);
begin
process (clk, cnt, rst, set)
begin
if (clk'event and clk = '1') then
if (rst = '0') then
cnt <= (others => '0');
elsif (set = '0') then
cnt <= (others => '1');
else
cnt <= cnt + '1';
end if;
end if;
end process;
count <= cnt;
end behave;