Azathoth42

Ondrovo, byte to 7 segment

Dec 17th, 2014
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.76 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity byte7seg is
  6.     port(
  7.         byte : in unsigned(7 downto 0);
  8.  
  9.         hex1 : out std_logic_vector(6 downto 0);
  10.         hex2 : out std_logic_vector(6 downto 0);
  11.         hex3 : out std_logic_vector(6 downto 0)
  12.     );
  13. end entity;
  14.  
  15. architecture dataflow of byte7seg is
  16. begin
  17.     process(byte)
  18.         variable b : integer;
  19.         variable ones : integer;
  20.         variable hundreds : integer;
  21.     begin
  22.         b := to_integer(byte);
  23.        
  24.         -- hundreds
  25.         if b >= 200 then
  26.             b := b - 200;
  27.             hundreds := 2;
  28.             hex3 <= "0100100"; -- 2
  29.         elsif b >= 100 then
  30.             b := b - 100;
  31.             hundreds := 1;
  32.             hex3 <= "1111001"; -- 1
  33.         else
  34.             hundreds := 0;
  35.             hex3 <= "1111111"; -- off
  36.         end if;
  37.        
  38.        
  39.         ones := b mod 10; -- ones
  40.         b := b - ones;    -- tens
  41.        
  42.         -- tens
  43.         case b is
  44.             WHEN 0 =>
  45.                 if hundreds > 0 then
  46.                     hex2 <= "1000000"; -- 0
  47.                 else
  48.                     hex2 <= "1111111"; -- blank
  49.                 end if;
  50.             WHEN 10 => hex2 <= "1111001";
  51.             WHEN 20 => hex2 <= "0100100";
  52.             WHEN 30 => hex2 <= "0110000";
  53.             WHEN 40 => hex2 <= "0011001";
  54.             WHEN 50 => hex2 <= "0010010"; -- 5
  55.             WHEN 60 => hex2 <= "0000010";
  56.             WHEN 70 => hex2 <= "1111000";
  57.             WHEN 80 => hex2 <= "0000000";
  58.             WHEN 90 => hex2 <= "0010000";
  59.             WHEN others => hex2 <= "1111111"; --fail - blank.
  60.         end case;
  61.  
  62.         -- ones
  63.         case ones is
  64.             WHEN 0 => hex1 <= "1000000"; -- 0
  65.             WHEN 1 => hex1 <= "1111001";
  66.             WHEN 2 => hex1 <= "0100100";
  67.             WHEN 3 => hex1 <= "0110000";
  68.             WHEN 4 => hex1 <= "0011001";
  69.             WHEN 5 => hex1 <= "0010010"; -- 5
  70.             WHEN 6 => hex1 <= "0000010";
  71.             WHEN 7 => hex1 <= "1111000";
  72.             WHEN 8 => hex1 <= "0000000";
  73.             WHEN 9 => hex1 <= "0010000";
  74.             WHEN others => hex1 <= "1111111"; --fail - blank.
  75.         end case;
  76.        
  77.     end process;
  78.    
  79. end dataflow;
Advertisement
Add Comment
Please, Sign In to add comment