简体   繁体   English

7段解码器将8位二进制数转换为十进制数

[英]Conversion of 8-bit binary number to decimal number for 7 segment decoder

I am currently a beginner programming to an FPGA board in VHDL using Quartus II. 我目前是使用Quartus II在VHDL中对FPGA板进行编程的初学者。 I need to convert an 8 bit number of type std_logic_vector to three separate 4 bit std_logic_vector variables so that i may display a decimal number on three 7 segment displays (the largest number in that will be dealt with is 254). 我需要将类型为std_logic_vector的8位数字转换为三个单独的4位std_logic_vector变量,以便我可以在三个7段显示器上显示一个十进制数字(将处理的最大数字为254)。 currently i am using repeated subtraction division to handle this, however in compilation the while loop which i use is unable to resolve within 10000 iterations. 目前,我正在使用重复减法除法来处理此问题,但是在编译中,我使用的while循环无法在10000次迭代中解决。 the loop is shown below: 循环如下所示:

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;

Any help or insight to this matter would be greatly appreciated. 任何帮助或有识之士对此将不胜感激。

I looks like you need `BCD converter. 我看来您需要`BCD转换器。

Have a look at this website 看看这个网站

8 bit binary to bcd convertor 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM