您当前的位置:五五电子网电子知识单片机-工控设备DSP/FPGA技术VHLD实例二进制到BCD码转换 正文
VHLD实例二进制到BCD码转换

VHLD实例二进制到BCD码转换

点击数:7956 次   录入时间:03-04 11:43:36   整理:http://www.55dianzi.com   DSP/FPGA技术
--
--
------------------------------------------------------------------------------------
-- DESCRIPTION   :  Bin to Bcd converter
--                  Input (data_in) width : 4
--                  Output (data_out) width : 8
--                  Enable (EN) active : high
--
-- Download from :  http://www.pld.com.cn
------------------------------------------------------------------------------------


library IEEE;
use IEEE.std_logIC_1164.all;

entity bin2bcd is
	port(
		data_in : in std_logic_vector(3 downto 0);
		EN : in std_logic;
		data_out : out std_logic_vector(7 downto 0)
	);
end entity;


architecture bin2bcd of bin2bcd is
begin

	process(data_in, EN)
	variable data_in_TEMP : std_logic_vector(2 downto 0);
	begin
		data_in_TEMP := data_in(3 downto 1);
		data_out <= (others => '0');
		if EN='1' then
			case data_in_TEMP is
				when "000" => data_out(7 downto 1) <= "0000000";
				when "001" => data_out(7 downto 1) <= "0000001";
				when "010" => data_out(7 downto 1) <= "0000010";
				when "011" => data_out(7 downto 1) <= "0000011";
				when "100" => data_out(7 downto 1) <= "0000100";
				when "101" => data_out(7 downto 1) <= "0001000";
				when "110" => data_out(7 downto 1) <= "0001001";
				when "111" => data_out(7 downto 1) <= "0001010";
				when others => data_out <= (others => '0');
			end case;

			data_out(0) <= data_in(0);
		end if;
	end process;

end architecture;



本文关键字:二进制  DSP/FPGA技术单片机-工控设备 - DSP/FPGA技术