Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.81 KB | None | 0 0
  1. library ieee;
  2.  
  3. use ieee.std_logic_1164.all;
  4. use ieee.std_logic_arith.all;
  5. use IEEE.STD_LOGIC_SIGNED.all;
  6.  
  7. entity zad2 is
  8. port(
  9.         iSW : in std_logic_vector(7 downto 0);
  10.         iINV: in std_logic;
  11.         oLED: out std_logic_vector(7 downto 0);
  12.         oSIGN: out std_logic;
  13.         oGREAT: out std_logic
  14.         );
  15. end entity;
  16.  
  17. architecture arch of zad2 is
  18.  
  19.     signal sA:std_logic_vector(2 downto 0);
  20.     signal sB:std_logic_vector(2 downto 0);
  21.     signal sREZ:std_logic_vector(3 downto 0);
  22.     signal sKOD:std_logic_vector(2 downto 0);
  23.  
  24.  
  25. begin
  26.  
  27.     sA <= iSW(6 downto 4) ;
  28.     sB <= iSW(2 downto 0) ;
  29.  
  30.  
  31. process (iSW,iINV,sREZ,sA,sB,sREZ,sKOD) begin
  32.  
  33. -- ako je INV 1
  34.     if (iINV = '1') then
  35.         oLED <= not iSW;
  36.        
  37.        
  38. -- ako je INV 0
  39.     else
  40.         oLED(4) <= '1';
  41.        
  42.     -- sabirac
  43.             if(sA(2) = '0' and sB(2) = '0') then
  44.            
  45.             sREZ <= ('0'&sA) + ('0'&sB);
  46.            
  47.         elsif(sA(2) = '1' and sB(2) = '0') then
  48.        
  49.             sREZ <=('1'&sA) + ('0'&sB);
  50.            
  51.         elsif(sA(2) = '0' and sB(2) = '1') then
  52.        
  53.             sREZ <= ('0'&sA) + ('1'&sB);
  54.            
  55.        else
  56.        
  57.             sREZ <= ('1'&sA) + ('1'&sB);
  58.            
  59.         end if;
  60.         oLED(3 downto 0) <= sREZ;
  61.        
  62.        
  63.     --paljenje crvene lampe
  64.         if(sREZ(3) = '1' ) then
  65.             oSIGN <= '1';
  66.         else
  67.             oSIGN <= '0';
  68.         end if;
  69.        
  70.         --rad LED 7-5(prioritetni koder)
  71.             if(iSW(0) = '1'  ) then
  72.                 sKOD <= "000";
  73.         elsif(iSW(1) = '1'  ) then
  74.                 sKOD <= "001";
  75.         elsif(iSW(2) = '1' ) then
  76.                 sKOD <= "010";
  77.         elsif(iSW(3) = '1'  ) then
  78.                 sKOD <= "011";
  79.         elsif(iSW(4) = '1'  ) then
  80.                 sKOD <= "100";
  81.         elsif(iSW(5) = '1'  ) then
  82.                 sKOD <= "101";
  83.         elsif(iSW(6) = '1'  ) then
  84.                 sKOD <= "110";
  85.         else
  86.                 sKOD <= "111";
  87.             end if;
  88.        
  89.             oLED(7 downto 5) <= sKOD;
  90.         --zelena dioda
  91.            
  92.             if(sA > sB) then
  93.                 oGREAT <= '1';
  94.             else
  95.                 oGREAT <= '0';
  96.        
  97.             end if;
  98.            
  99.        
  100.     end if;
  101.     end process;
  102.  
  103. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement