Guest User

Untitled

a guest
May 18th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 7.20 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Engineer:         Pasquale Boemio
  3. --
  4. -- Create Date:    17:48:53 01/03/2012
  5. -- Module Name:    SevenSegmentDisplay - Behavioral
  6. -- Project Name:     ALUProject
  7. -- Target Devices: xc3s1200e-4fg320
  8. -- Description:      Modulo utilizzato per rappresentare un numero sul display
  9. --                   (viene effettuata anche la conversione bin to hex)
  10. --
  11. -- Revision 0.01 - File Created
  12. ----------------------------------------------------------------------------------
  13. library IEEE;
  14. use IEEE.STD_LOGIC_1164.ALL;
  15.  
  16. -----------------------------------------------
  17. -- Vista esterna del blocco SevenSegmentDisplay
  18. -----------------------------------------------
  19. entity SevenSegmentDisplay is
  20.     Port ( cifre : in  STD_LOGIC_VECTOR (7 downto 0);
  21.            clock : in  STD_LOGIC;
  22.               complement : in STD_LOGIC;
  23.            anodi : inout  STD_LOGIC_VECTOR (3 downto 0) := "1110";
  24.            sevenSegments : out  STD_LOGIC_VECTOR (6 downto 0));
  25. end SevenSegmentDisplay;
  26. -----------------------------------------------
  27.  
  28. architecture Behavioral of SevenSegmentDisplay is
  29.  
  30. ----------------------------------------
  31. -- Definizione di un blocco ClockSpeeder
  32. ----------------------------------------
  33. component clockGenerator
  34.     Port ( slowerClock : in STD_LOGIC;
  35.              fasterClock : out STD_LOGIC);
  36. end component clockGenerator;            
  37. for innerClockGenerator : clockGenerator use entity ClockSpeeder(Behavioral);
  38. ----------------------------------------
  39.  
  40. ---------------------------------------------
  41. -- Definizione di un segnale di clock interno
  42. ---------------------------------------------
  43. signal innerClock : STD_LOGIC;
  44. ---------------------------------------------
  45.  
  46. -----------------------------------------
  47. -- Definizione delle codifiche dei numeri
  48. -----------------------------------------
  49. constant zero : STD_LOGIC_VECTOR(6 downto 0) := "1000000";
  50. constant uno : STD_LOGIC_VECTOR(6 downto 0) := "1111001";
  51. constant due : STD_LOGIC_VECTOR(6 downto 0) := "0100100";
  52. constant tre : STD_LOGIC_VECTOR(6 downto 0) := "0110000";
  53. constant quattro : STD_LOGIC_VECTOR(6 downto 0) := "0011001";
  54. constant cinque : STD_LOGIC_VECTOR(6 downto 0) := "0010010";
  55. constant sei : STD_LOGIC_VECTOR(6 downto 0) := "0000010";
  56. constant sette : STD_LOGIC_VECTOR(6 downto 0) := "1111000";
  57. constant otto : STD_LOGIC_VECTOR(6 downto 0) := "0000000";
  58. constant nove : STD_LOGIC_VECTOR(6 downto 0) := "0010000";
  59. constant a : STD_LOGIC_VECTOR(6 downto 0) := "0001000";
  60. constant b : STD_LOGIC_VECTOR(6 downto 0) := "0000011";
  61. constant c : STD_LOGIC_VECTOR(6 downto 0) := "1000110";
  62. constant d : STD_LOGIC_VECTOR(6 downto 0) := "0100001";
  63. constant e : STD_LOGIC_VECTOR(6 downto 0) := "0000110";
  64. constant f : STD_LOGIC_VECTOR(6 downto 0) := "0001110";
  65. constant minSimbol : STD_LOGIC_VECTOR(6 downto 0) := "0111111";
  66.  
  67.  
  68. signal firstHex : STD_LOGIC_VECTOR(6 downto 0) := zero;
  69. signal secondHex : STD_LOGIC_VECTOR(6 downto 0) := zero;
  70. signal sign : STD_LOGIC_VECTOR(6 downto 0) := "1111111";
  71. -----------------------------------------
  72.  
  73. -------------------------------------------------------------------
  74. -- Segnali utilizzati per suddividere il numero nelle due cifre hex
  75. -------------------------------------------------------------------
  76. signal lessSignificative : STD_LOGIC_VECTOR(3 downto 0);
  77. signal moreSignificative : STD_LOGIC_VECTOR(3 downto 0);  
  78. -------------------------------------------------------------------
  79.  
  80. begin
  81.  
  82. innerClockGenerator : clockGenerator port map(clock, innerClock); -- Cablaggio del generatore di clock
  83.  
  84. --------------------------------------------------
  85. -- Processo che mostra le cifre su ciascun display
  86. --------------------------------------------------
  87. display_process : process(innerClock) begin
  88.     if innerClock'event and innerClock = '1' then
  89.         case anodi is
  90.             when "1110" => sevenSegments <= firstHex; --firstHex;
  91.                                 anodi <= "1101";
  92.             when "1101" => sevenSegments <= secondHex;
  93.                                 anodi <= "1011";
  94.             when "1011" => sevenSegments <= "0001001";
  95.                                 anodi <="0111";
  96.             when "0111" => sevenSegments <= sign;
  97.                                 anodi <= "1110";
  98.             when others => null;
  99.         end case;
  100.     end if;
  101. end process display_process;
  102. --------------------------------------------------
  103.  
  104. ---------------------------------------------------------
  105. -- Processo che codifica le cifre per essere visualizzate
  106. ---------------------------------------------------------
  107. numberDecoder_process: process(cifre)
  108. begin  
  109.     lessSignificative <= cifre(3 downto 0);
  110.     moreSignificative <= cifre(7 downto 4);
  111.    
  112.     if complement = '0' then
  113.         case lessSignificative is
  114.             when "0000" => firstHex <= zero;
  115.             when "0001" => firstHex <= uno;
  116.             when "0010" => firstHex <= due;
  117.             when "0011" => firstHex <= tre;
  118.             when "0100" => firstHex <= quattro;
  119.             when "0101" => firstHex <= cinque;
  120.             when "0110" => firstHex <= sei;
  121.             when "0111" => firstHex <= sette;
  122.             when "1000" => firstHex <= otto;
  123.             when "1001" => firstHex <= nove;
  124.             when "1010" => firstHex <= a;
  125.             when "1011" => firstHex <= b;
  126.             when "1100" => firstHex <= c;
  127.             when "1101" => firstHex <= d;
  128.             when "1110" => firstHex <= e;
  129.             when "1111" => firstHex <= f;
  130.             when others => null;
  131.         end case;
  132.    
  133.         case moreSignificative is
  134.             when "0000" => secondHex <= zero;
  135.             when "0001" => secondHex <= uno;
  136.             when "0010" => secondHex <= due;
  137.             when "0011" => secondHex <= tre;
  138.             when "0100" => secondHex <= quattro;
  139.             when "0101" => secondHex <= cinque;
  140.             when "0110" => secondHex <= sei;
  141.             when "0111" => secondHex <= sette;
  142.             when "1000" => secondHex <= otto;
  143.             when "1001" => secondHex <= nove;
  144.             when "1010" => secondHex <= a;
  145.             when "1011" => secondHex <= b;
  146.             when "1100" => secondHex <= c;
  147.             when "1101" => secondHex <= d;
  148.             when "1110" => secondHex <= e;
  149.             when "1111" => secondHex <= f;
  150.             when others => null;
  151.         end case;
  152.        
  153.         sign <= "1111111";
  154.     else
  155.         case lessSignificative is
  156.             when "0000" => firstHex <= zero;
  157.             when "0001" => firstHex <= f;
  158.             when "0010" => firstHex <= e;
  159.             when "0011" => firstHex <= d;
  160.             when "0100" => firstHex <= c;
  161.             when "0101" => firstHex <= b;
  162.             when "0110" => firstHex <= a;
  163.             when "0111" => firstHex <= nove;
  164.             when "1000" => firstHex <= otto;
  165.             when "1001" => firstHex <= sette;
  166.             when "1010" => firstHex <= sei;
  167.             when "1011" => firstHex <= cinque;
  168.             when "1100" => firstHex <= quattro;
  169.             when "1101" => firstHex <= tre;
  170.             when "1110" => firstHex <= due;
  171.             when "1111" => firstHex <= uno;
  172.             when others => null;
  173.         end case;
  174.    
  175.         case moreSignificative is
  176.             when "0000" => secondHex <= zero;
  177.             when "0001" => secondHex <= uno;
  178.             when "0010" => secondHex <= due;
  179.             when "0011" => secondHex <= tre;
  180.             when "0100" => secondHex <= quattro;
  181.             when "0101" => secondHex <= cinque;
  182.             when "0110" => secondHex <= sei;
  183.             when "0111" => secondHex <= sette;
  184.             when "1000" => secondHex <= sette;
  185.             when "1001" => secondHex <= sei;
  186.             when "1010" => secondHex <= cinque;
  187.             when "1011" => secondHex <= quattro;
  188.             when "1100" => secondHex <= tre;
  189.             when "1101" => secondHex <= due;
  190.             when "1110" => secondHex <= uno;
  191.             when "1111" => secondHex <= zero;
  192.             when others => null;
  193.         end case;
  194.        
  195.         if moreSignificative(3)='1' then
  196.             sign <= minSimbol;
  197.         else
  198.             sign <= "0000000";
  199.         end if;
  200.        
  201.     end if;
  202.  
  203. end process numberDecoder_process;
  204. ---------------------------------------------------------
  205.  
  206. end Behavioral;
Add Comment
Please, Sign In to add comment