library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY bcd IS
PORT (
clk : IN std_logic;
rst : IN std_logic;
a : IN std_logic_vector(3 DOWNTO 0);
c : OUT std_logic_vector(7 DOWNTO 0);
en : OUT std_logic_vector(7 DOWNTO 0));
END bcd;
ARCHITECTURE arch OF bcd IS
SIGNAL code_data : std_logic_vector(7 DOWNTO 0);
SIGNAL c_tmp : std_logic_vector(3 DOWNTO 0);
SIGNAL cnt : std_logic_vector(19 DOWNTO 0);
SIGNAL en_tmp : std_logic_vector(1 DOWNTO 0);
BEGIN
IF (NOT rst = '1') THEN
cnt <= "00000000000000000000";
ELSIF(clk'event and clk='0')THEN
IF (cnt /= "01011111111111111111") THEN
cnt <= cnt + "00000000000000000001";
ELSE
cnt <= "00000000000000000000";
END IF;
END IF;
END PROCESS;
PROCESS(clk,rst)
BEGIN
IF (NOT rst = '1') THEN
en_tmp <= "01";
ELSIF(clk'event and clk='0')THEN
IF (cnt = "01011111111111111111") THEN
en_tmp <= NOT en_tmp;
END IF;
END IF;
END PROCESS;
PROCESS(en_tmp)
BEGIN
CASE en_tmp IS
WHEN "01" =>
c_tmp <= code_data(3 DOWNTO 0);
WHEN "10" =>
c_tmp <= code_data(7 DOWNTO 4);
WHEN OTHERS =>
c_tmp <= "0000";
END CASE;
END PROCESS;
PROCESS(a)
BEGIN
CASE a(3 DOWNTO 1) IS
WHEN "000" =>
code_data(7 DOWNTO 1) <= "0000000";
WHEN "001" =>
code_data(7 DOWNTO 1) <= "0000001";
WHEN "010" =>
code_data(7 DOWNTO 1) <= "0000010";
WHEN "011" =>
code_data(7 DOWNTO 1) <= "0000011";
WHEN "100" =>
code_data(7 DOWNTO 1) <= "0000100";
WHEN "101" =>
code_data(7 DOWNTO 1) <= "0001000";
WHEN "110" =>
code_data(7 DOWNTO 1) <= "0001001";
WHEN "111" =>
code_data(7 DOWNTO 1) <= "0001010";
WHEN OTHERS =>
code_data(7 DOWNTO 1) <= "0000000";
END CASE;
code_data(0) <= a(0);
END PROCESS;
PROCESS(c_tmp)
BEGIN
CASE c_tmp IS
WHEN "0000" =>
c <= "00000011";
WHEN "0001" =>
c <= "10011111";
WHEN "0010" =>
c <= "00100101";
WHEN "0011" =>
c <= "00001101";
WHEN "0100" =>
c <= "10011001";
WHEN "0101" =>
c <= "01001001";
WHEN "0110" =>
c <= "01000001";
WHEN "0111" =>
c <= "00011111";
WHEN "1000" =>
c <= "00000001";
WHEN "1001" =>
c <= "00011001";
WHEN "1010" =>
c <= "00010001";
WHEN "1011" =>
c <= "11000001";
WHEN "1100" =>
c <= "01100011";
WHEN "1101" =>
c <= "10000101";
WHEN "1110" =>
c <= "01100001";
WHEN "1111" =>
c <= "01110001";
WHEN OTHERS =>
NULL;