Guest User

Untitled

a guest
Jul 2nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.80 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_unsigned.all;
  4.  
  5. entity tp7 is
  6.    port (
  7.          clk, load: in std_logic;
  8.          b: in std_logic_vector(7 downto 0);
  9.          z, notz, dsel, dp: out std_logic);
  10. end tp7;
  11.  
  12. architecture comp of tp7 is
  13. type state is (par,impar);
  14. signal st, nst: state;
  15. signal w,p,clear,sel,d,dmux: std_logic;
  16. signal c: std_logic_vector(2 downto 0);
  17. signal aux: std_logic_vector (7 downto 0);
  18. begin
  19.  
  20.     -- maquina de estado
  21.     process (clk,load)
  22.     begin
  23.         if load = '1' then
  24.             st<=par;
  25.         elsif (clk'event and clk='1') then
  26.             st<=nst;
  27.         end if;
  28.     end process;
  29.    
  30.    
  31.     process (clk,w)
  32.     begin
  33.         case st is
  34.             when par=>   if w='0' then
  35.                             nst<=par;
  36.                        else
  37.                             nst<=impar;
  38.                        end if;
  39.                        
  40.             when impar=>   if w='0' then
  41.                             nst<=impar;
  42.                        else
  43.                             nst<=par;
  44.                        end if;
  45.         end case;                  
  46.     end process;
  47.    
  48.     process (st)
  49.     begin  
  50.         if (st=par) then
  51.             p<='0';
  52.         else
  53.             p<='1';
  54.         end if;
  55.     end process;
  56.    
  57.    
  58.     --contador
  59.     clear <= not load;
  60.     process (clk,clear)
  61.     begin
  62.         if clear = '0' then
  63.             c<=(others=>'0');
  64.         elsif (clk'event and clk='1') then
  65.             c<=c+1;
  66.         end if;
  67.     end process;
  68.    
  69.     --and
  70.     process (c)
  71.     begin
  72.         sel <= c(0) and c(1) and c(2);
  73.         dsel <= sel;
  74.     end process;
  75.    
  76.     --mux
  77.     process (p,w)
  78.     begin
  79.         if (sel='0') then
  80.             dmux<=w;
  81.         else
  82.             dmux<=p;
  83.         end if;
  84.     end process;
  85.    
  86.     --ShiftRegister
  87.     process (load, b, clk)
  88.     begin
  89.         if load = '1' then
  90.             aux<=b;
  91.         elsif (clk'event and clk='1') then
  92.             aux(7) <= '0';
  93.             for i in 6 downto 0 loop
  94.                 aux(i) <= aux(i+1);
  95.             end loop;
  96.            
  97.         end if;w <= aux(0);
  98.     end process;
  99.    
  100.     --FlipFlop
  101.     process(clk, dmux)
  102.     begin
  103.       if (clk'event and clk='1') then
  104.         z <= dmux;
  105.         notz <= not dmux;
  106.       end if;
  107.     end process;
  108.  
  109.  
  110. end comp;
Add Comment
Please, Sign In to add comment