Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.08 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3.  
  4. -- Uncomment the following library declaration if using
  5. -- arithmetic functions with Signed or Unsigned values
  6. use IEEE.NUMERIC_STD.ALL;
  7.  
  8. -- Uncomment the following library declaration if instantiating
  9. -- any Xilinx leaf cells in this code.
  10. --library UNISIM;
  11. --use UNISIM.VComponents.all;
  12.  
  13. entity BINtoBCD is
  14.     Port ( c  : in STD_LOGIC;
  15.            S3 : in STD_LOGIC;
  16.            S2 : in STD_LOGIC;
  17.            S1 : in STD_LOGIC;
  18.            S0 : in STD_LOGIC;
  19.            bcd1 : out STD_LOGIC_VECTOR(3 downto 0);
  20.            bcd0 : out STD_LOGIC_VECTOR(3 downto 0));
  21.                      
  22. end BINtoBCD;
  23.  
  24. architecture Behavioral of BINtoBCD is
  25. signal truth: std_logic_vector(4 downto 0);
  26. signal int: unsigned(4 downto 0);
  27. signal digit0: unsigned(4 downto 0);
  28. signal digit1: unsigned(4 downto 0);
  29.  
  30. begin
  31.  truth <= c & s3 & s2 & s1 & s0;
  32.  int <= unsigned(truth);
  33.  digit0 <= int mod 10;
  34.  digit1 <= int / 10;
  35.  
  36.  bcd0 <= std_logic_vector(digit0(3 downto 0));
  37.  bcd1 <= std_logic_vector(digit1(3 downto 0));
  38.      
  39. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement