trafka

VHDL LAB 5 CW6 RAM

Apr 12th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.60 KB | None | 0 0
  1. Library IEEE;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. entity RAM is
  6.     port(
  7.         key : IN STD_LOGIC;
  8.         clk : IN STD_LOGIC :='1';
  9.         sw  : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
  10.         wr  : IN STD_LOGIC;
  11.         HEX0    : OUT STD_LOGIC_VECTOR (0 TO 6);
  12.         HEX1    : OUT STD_LOGIC_VECTOR (0 TO 6)
  13.     );
  14. end RAM;
  15.  
  16. architecture rtl of RAM is
  17. component RAM1PORT
  18.     PORT
  19.     (
  20.         adres   : IN STD_LOGIC_VECTOR (4 DOWNTO 0);
  21.         clock   : IN STD_LOGIC :='1';
  22.         data    : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
  23.         wren    : IN STD_LOGIC;
  24.         q   : OUT STD_LOGIC_VECTOR (7 DOWNTO 0)
  25.     );
  26. end component;
  27.  
  28. component hex7seg
  29.     PORT (  hex : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
  30.         display : OUT STD_LOGIC_VECTOR (0 to 6)
  31.     );
  32. end component;
  33.  
  34. signal currentCount : STD_LOGIC_VECTOR (4 DOWNTO 0);
  35. signal output       : STD_LOGIC_VECTOR (7 DOWNTO 0);
  36. alias bit3_0        : STD_LOGIC_VECTOR (3 DOWNTO 0) is output (3 downto 0);
  37. alias bit7_4        : STD_LOGIC_VECTOR (3 DOWNTO 0) is output (7 downto 4);
  38.  
  39. signal HEXTMP0  :  STD_LOGIC_VECTOR (0 TO 6);
  40. signal HEXTMP1  :  STD_LOGIC_VECTOR (0 TO 6);
  41.  
  42. begin
  43.  
  44.     MEM : RAM1PORT port map (adress=>currentCount, clock=>clk, data=>sw, wren=>wr,
  45.         q=>output);
  46.     SEG0: hex7seg port map (hex=>bit3_0, display=>HEXTMP0);
  47.     SEG1: hex7seg port map (hex=>bit7_4, display=>HEXTMP1);
  48.  
  49.     process(key)
  50.     begin
  51.         if(key='0' and key'event) then
  52.             if(currentCount="11111") then
  53.                 currentCount <= "00000";
  54.             else
  55.                 currentCount <= currentCount + '1';
  56.             end if;
  57.         end if;
  58.     end process;
  59.  
  60.     process(output)
  61.     begin
  62.         HEX0 <= HEXTMP0;
  63.         HEX1 <= HEXTMP1;
  64.     end process;
  65.  
  66.     process(output)
  67.     begin
  68.         HEX0 <= HEXTMP0;
  69.         HEX1 <= HEXTMP1;
  70.     end process;
  71. end rtl;
  72.  
  73. -- EXTRAAAA DRUGI PLIK HEJKA
  74.  
  75. Library IEEE;
  76. use ieee.std_logic_1164.all;
  77.  
  78. ENTITY hex7seg IS
  79.     PORT (  hex : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
  80.         display : OUT STD_LOGIC_VECTOR (0 TO 6)
  81.     );
  82. end hex7seg;
  83.  
  84. ARCHITECTURE Behavior OF hex7seg IS
  85. BEGIN
  86.     PROCESS (hex)
  87.     BEGIN
  88.         CASE (hex) IS
  89.             WHEN "0000" => display <= "0000001";
  90.             WHEN "0001" => display <= "1001111";
  91.             WHEN "0010" => display <= "0010010";
  92.             WHEN "0011" => display <= "0000110";
  93.             WHEN "0100" => display <= "1001100";
  94.             WHEN "0101" => display <= "0100100";
  95.             WHEN "0110" => display <= "1100000";
  96.             WHEN "0111" => display <= "0001111";
  97.             WHEN "1000" => display <= "0000000";
  98.             WHEN "1001" => display <= "0001100";
  99.             WHEN "0010" => display <= "0001000";
  100.             WHEN "1011" => display <= "1100000";
  101.             WHEN "1100" => display <= "0110001";
  102.             WHEN "1101" => display <= "1000010";
  103.             WHEN "1110" => display <= "0110000";
  104.             WHEN OTHERS => display <= "0111000";
  105.         END CASE;
  106.     END PROCESS;
  107. END Behavior;
Advertisement
Add Comment
Please, Sign In to add comment