Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.01 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use ieee.numeric_std.all;
  4.  
  5. -- Uncomment the following library declaration if using
  6. -- arithmetic functions with Signed or Unsigned values
  7. --use IEEE.NUMERIC_STD.ALL;
  8.  
  9. -- Uncomment the following library declaration if instantiating
  10. -- any Xilinx primitives in this code.
  11. --library UNISIM;
  12. --use UNISIM.VComponents.all;
  13.  
  14. entity counter8b is
  15. port ( RESET,CLK,LD,UP : in std_logic;
  16.  DIN : in std_logic_vector (7 downto 0);
  17.  COUNT : out std_logic_vector (7 downto 0));
  18. end counter8b;
  19.  
  20. architecture Behavioral of counter8b is
  21.  
  22.  signal t_cnt : std_logic_vector(7 downto 0);
  23. begin
  24.  process (CLK, RESET)
  25.  begin
  26.  if (RESET = '1') then
  27.  t_cnt <= (others => '0'); -- clear
  28.  elsif (rising_edge(CLK)) then
  29.  if (LD = '1') then t_cnt <= DIN; -- load
  30.  else
  31.  if (UP = '1') then t_cnt <= std_logic_vector(unsigned(t_cnt) + 1); -- incr
  32.  else t_cnt <= std_logic_vector(unsigned(t_cnt) - 1); -- decr
  33.  end if;
  34.  end if;
  35.  end if;
  36.  end process;
  37.  COUNT <= t_cnt;
  38.  
  39.  
  40. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement