Advertisement
Guest User

UCISW zamek szyfrowy VHDL

a guest
Nov 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.37 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.NUMERIC_STD.ALL;
  4.  
  5. library UNISIM;
  6. use UNISIM.VComponents.all;
  7.  
  8. entity zamek_szyfrowy is
  9.     Port ( clock : in  STD_LOGIC;
  10.            reset : in  STD_LOGIC;
  11.            Z : in  STD_LOGIC;
  12.            Y : out  STD_LOGIC;
  13.               SEG7 : out STD_LOGIC_VECTOR (7 downto 0));
  14. end zamek_szyfrowy;
  15.  
  16. -- clock, reset oczywiste
  17. -- Z - wejscie
  18. -- Y - wyjscie na diode (zapalenie / zgaszenie)
  19. -- SEG7 - wyjscie na wyswietlacz 7-seg, kazdy stan przedstawia
  20.  
  21. architecture Behavioral of zamek_szyfrowy is
  22. type state_type is (q0, q1, q2, q3, q4, q5);    -- wszystkie mozliwe stany
  23. signal state, next_state: state_type;   -- deklaracja stanow typu state_type
  24.  
  25. begin
  26.     clockSet: process (clock, reset)
  27.     begin
  28.         if (reset = '1') then   -- po wcisnieciu przycisku reset
  29.             state <= q0;
  30.         elsif rising_edge(clock) then   -- pojawienie sie narastajacego zbocza fali zegara
  31.             state <= next_state;    -- zmiana stanu na kolejny
  32.         end if;
  33.     end process;
  34.    
  35.     stateChange: process (state, Z)
  36.     begin
  37.         case state is
  38.             when q0 =>
  39.                 if Z ='1' then
  40.                     next_state <= q0;
  41.                 else
  42.                     next_state <= q1;
  43.                 end if;
  44.             when q1 =>
  45.                 if Z ='1' then
  46.                     next_state <= q2;
  47.                 else
  48.                     next_state <= q1;
  49.                 end if;
  50.             when q2 =>
  51.                 if Z ='1' then
  52.                     next_state <= q0;
  53.                 else
  54.                     next_state <= q3;
  55.                 end if;
  56.             when q3 =>
  57.                 if Z ='1' then
  58.                     next_state <= q4;
  59.                 else
  60.                     next_state <= q1;
  61.                 end if;
  62.             when q4 =>
  63.                 if Z ='1' then
  64.                     next_state <= q0;
  65.                 else
  66.                     next_state <= q5;
  67.                 end if;
  68.             when q5 =>
  69.                 if Z ='1' then
  70.                     next_state <= q0;
  71.                 else
  72.                     next_state <= q1;
  73.                 end if;
  74.         end case;
  75.     end process;
  76.            
  77.     outputLED: process (state)  -- dioda reprezentujaca wyjscie Y
  78.     begin
  79.         case state is
  80.             when q0 => y <= '1';    -- zgaszona dioda
  81.             when q1 => y <= '1';
  82.             when q2 => y <= '1';
  83.             when q3 => y <= '1';
  84.             when q4 => y <= '1';
  85.             when q5 => y <= '0';    -- zapalona dioda
  86.         end case;
  87.     end process;
  88.    
  89.     output7SEG: process (state) -- wyswietlacz 7-segmentowny reprezentujacy
  90.     begin                                   -- kolejne stany
  91.         case state is
  92.             when q0 => SEG7 <= "11000000";  -- pgfedbca
  93.             when q1 => SEG7 <= "11111001";
  94.             when q2 => SEG7 <= "10100100";
  95.             when q3 => SEG7 <= "10110000";
  96.             when q4 => SEG7 <= "10011001";
  97.             when q5 => SEG7 <= "10010010";
  98.         end case;
  99.     end process;
  100.  
  101. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement