用于7段解码器的8位二进制数到十进制数的转换



我目前是一名使用Quartus II在VHDL中编程FPGA板的初学者。我需要将类型为std_logic_vector的8位数字转换为三个单独的4位std_logic_vector变量,以便我可以在三个7段显示器上显示一个十进制数字(将处理的最大数字是254)。目前我正在使用重复减法除法来处理这个问题,但是在编译中,我使用的while循环无法在10000次迭代中解决。循环如下所示:

while (rmdr > "000000000") loop
                while (rmdr > "000001001") loop
                    while (rmdr > "001100011") loop
                        dig2 := dig2 + '1';
                        rmdr := rmdr - "001100100";
                    end loop;
                    dig1 := dig1 + '1';
                    rmdr := rmdr - "000001010";
                end loop;
                dig0 := dig0 + '1';
                rmdr := rmdr - "000000001";
            end loop;

如对此事有任何帮助或见解,我们将不胜感激。

我觉得你需要`BCD转换器。

看看这个网站

8位二进制到bcd转换器

function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector is
variable i : integer:=0;
variable bcd : std_logic_vector(11 downto 0) := (others => '0');
variable bint : std_logic_vector(7 downto 0) := bin;
begin
for i in 0 to 7 loop  -- repeating 8 times.
bcd(11 downto 1) := bcd(10 downto 0);  --shifting the bits.
bcd(0) := bint(7);
bint(7 downto 1) := bint(6 downto 0);
bint(0) :='0';

if(i < 7 and bcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4.
bcd(3 downto 0) := bcd(3 downto 0) + "0011";
end if;
if(i < 7 and bcd(7 downto 4) > "0100") then --add 3 if BCD digit is greater than 4.
bcd(7 downto 4) := bcd(7 downto 4) + "0011";
end if;
if(i < 7 and bcd(11 downto 8) > "0100") then  --add 3 if BCD digit is greater than 4.
bcd(11 downto 8) := bcd(11 downto 8) + "0011";
end if;

end loop;
return bcd;
end to_bcd;

最新更新