Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
- entity byte7seg is
- port(
- byte : in unsigned(7 downto 0);
- hex1 : out std_logic_vector(6 downto 0);
- hex2 : out std_logic_vector(6 downto 0);
- hex3 : out std_logic_vector(6 downto 0)
- );
- end entity;
- architecture dataflow of byte7seg is
- begin
- process(byte)
- variable b : integer;
- variable ones : integer;
- variable hundreds : integer;
- begin
- b := to_integer(byte);
- -- hundreds
- if b >= 200 then
- b := b - 200;
- hundreds := 2;
- hex3 <= "0100100"; -- 2
- elsif b >= 100 then
- b := b - 100;
- hundreds := 1;
- hex3 <= "1111001"; -- 1
- else
- hundreds := 0;
- hex3 <= "1111111"; -- off
- end if;
- ones := b mod 10; -- ones
- b := b - ones; -- tens
- -- tens
- case b is
- WHEN 0 =>
- if hundreds > 0 then
- hex2 <= "1000000"; -- 0
- else
- hex2 <= "1111111"; -- blank
- end if;
- WHEN 10 => hex2 <= "1111001";
- WHEN 20 => hex2 <= "0100100";
- WHEN 30 => hex2 <= "0110000";
- WHEN 40 => hex2 <= "0011001";
- WHEN 50 => hex2 <= "0010010"; -- 5
- WHEN 60 => hex2 <= "0000010";
- WHEN 70 => hex2 <= "1111000";
- WHEN 80 => hex2 <= "0000000";
- WHEN 90 => hex2 <= "0010000";
- WHEN others => hex2 <= "1111111"; --fail - blank.
- end case;
- -- ones
- case ones is
- WHEN 0 => hex1 <= "1000000"; -- 0
- WHEN 1 => hex1 <= "1111001";
- WHEN 2 => hex1 <= "0100100";
- WHEN 3 => hex1 <= "0110000";
- WHEN 4 => hex1 <= "0011001";
- WHEN 5 => hex1 <= "0010010"; -- 5
- WHEN 6 => hex1 <= "0000010";
- WHEN 7 => hex1 <= "1111000";
- WHEN 8 => hex1 <= "0000000";
- WHEN 9 => hex1 <= "0010000";
- WHEN others => hex1 <= "1111111"; --fail - blank.
- end case;
- end process;
- end dataflow;
Advertisement
Add Comment
Please, Sign In to add comment