Advertisement
Sothian

Lab8

Nov 30th, 2019
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.14 KB | None | 0 0
  1. library ieee ;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. entity pwm is
  6.     port( writedata: in std_logic_vector(31 downto 0);
  7.         clk_clk, reset_reset_n:   in std_logic;
  8.         wr, cs : in std_logic;
  9.         display: out std_logic_vector(6 downto 0);
  10.         led: out std_logic_vector(1 downto 0)
  11.     );
  12. end pwm;
  13.  
  14. architecture rtl of pwm is
  15.     signal reg: std_logic_vector(4 downto 0);
  16. begin
  17.  
  18.     process(clk_clk)
  19.     begin
  20.        if (clk_clk'event and clk_clk = '1') then
  21.             if (wr = '1' and cs = '1') then
  22.                 reg <= writedata(4 downto 0);
  23.             end if;
  24.         end if;
  25.     end process;
  26.  
  27.     process(clk_clk)
  28.     begin
  29.         if (clk_clk'event and clk_clk = '1') then
  30.             CASE reg IS
  31.                 WHEN "00000" => display <= "1000000";   --0                                    
  32.                 WHEN "00001" => display <= "1111001";   --1
  33.                 WHEN "00010" => display <= "0100100";   --2
  34.                 WHEN "00011" => display <= "0110000";   --3
  35.                 WHEN "00100" => display <= "0011001";   --4
  36.                 WHEN "00101" => display <= "0010010";   --5
  37.                 WHEN "00110" => display <= "0000010";   --6
  38.                 WHEN "00111" => display <= "1111000";   --7
  39.                 WHEN "01000" => display <= "0000000";   --8
  40.                 WHEN "01001" => display <= "0010000";   --9
  41.                 WHEN OTHERS => display <=  "0000110";   --E
  42.             END CASE;
  43.            
  44.             if (reg = "00000") then
  45.                 LED <= "00";
  46.             elsif (reg = "00001" or reg = "00010" or reg = "00011" or reg = "00100" or reg = "00101" or reg = "00110"  or reg = "00111"  or reg = "01000"  or reg = "01001") then
  47.                 LED <= "01"; -- led swieci
  48.             elsif (reg = "10001" or reg = "10010" or reg = "10011" or reg = "10100" or reg = "10101" or reg = "10110"  or reg = "10111"  or reg = "11000"  or reg = "11001"  or reg = "11010")
  49.                 then LED <= "11"; --led i error swieci
  50.             else
  51.                 LED <= "10"; -- error swieci
  52.             end if;
  53.         end if;
  54.     end process;
  55.  
  56. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement