将整数值转换为ASCII字符 - VHDL

时间:2016-05-03 09:43:45

标签: vhdl hardware

我需要在2x16显示屏上显示一些整数值,但显示屏只能识别ASCII字符。所以在我向显示器发送一些值之前,我需要将它转换为字符串...任何想法?

非常感谢!

2 个答案:

答案 0 :(得分:0)

也许查找一个表会很有用。将ASCII字符存储在某处,并有一个方法将ASCII映射到"整数。"我认为你使用的是标准的INTEGER类型?无论哪种方式,它当前所处的格式应该能够以某种方式映射到ASCII,如果它还没有。

答案 1 :(得分:0)

有办法做到这一点。所以在开始时你需要将整数转换为std_logic_vector然后将该值转换为BCD系统,因此你有一个整数值的每个数字的二进制值。然后只需将每个数字的ASCII值保存到std_logic_vector-s数组中,这样就可以显示它们......

type     x_digits is array ( 3 downto 1) of natural;
signal   x_digit_tb : x_digits;
constant d0 : std_logic_vector (7 downto 0) := "00110000"; -- \\
constant d1 : std_logic_vector (7 downto 0) := "00110001"; -- ||
constant d2 : std_logic_vector (7 downto 0) := "00110010"; -- ||
constant d3 : std_logic_vector (7 downto 0) := "00110011"; -- ||
constant d4 : std_logic_vector (7 downto 0) := "00110100"; -- \\
constant d5 : std_logic_vector (7 downto 0) := "00110101"; --  >> Constant ASCII-binary value of digits 0 to 9
constant d6 : std_logic_vector (7 downto 0) := "00110110"; -- //
constant d7 : std_logic_vector (7 downto 0) := "00110111"; -- ||
constant d8 : std_logic_vector (7 downto 0) := "00111000"; -- ||
constant d9 : std_logic_vector (7 downto 0) := "00111001"; -- //
.
.
  process(CLK)
          ----- Convert X to BCD -----
          if CLK'event and clk = '1' and dX0 = 1 then
                x_shift(7 downto 0) := x_ein_local;
                for l in 0 to 7 loop
                    x_shift := x_shift sll 1;
                    if  l < 7 and x_shift(11 downto 8) > "0100" then
                        x_shift(11 downto  8) := x_shift(11 downto  8) + "0011";
                    end if;
                    if  l < 7 and x_shift(15 downto 12) > "0100" then
                        x_shift(15 downto 12) := x_shift(15 downto 12) + "0011";
                    end if;
                    if  l < 7 and x_shift(19 downto 16) > "0100" then
                        x_shift(19 downto 16) := x_shift(19 downto 16) + "0011";
                    end if;
                end loop;
                x_BCD <= x_shift(19 downto  8);
                x_shift := (others => '0');
                dX0 <= 2;
            ---- Convert X to ASCII --------    
            if CLK'event and clk = '1' and dX0 = 2 then
                for k in 1 to 3 loop
                    case k is
                        when 1 => WW := x_BCD( 3 downto  0);
                        when 2 => WW := x_BCD( 7 downto  4);
                        when 3 => WW := x_BCD(11 downto  8);
                    end case;
                    case WW is
                        when "0000" => x_digit(k) <= d0;
                        when "0001" => x_digit(k) <= d1;
                        when "0010" => x_digit(k) <= d2;
                        when "0011" => x_digit(k) <= d3;
                        when "0100" => x_digit(k) <= d4;
                        when "0101" => x_digit(k) <= d5;
                        when "0110" => x_digit(k) <= d6;
                        when "0111" => x_digit(k) <= d7;
                        when "1000" => x_digit(k) <= d8;
                        when "1001" => x_digit(k) <= d9;
                        when others => null;
                    end case;   
                end loop;
                dX0 <= 3;
            end if;
        end if;
 end process;

x_digits中保存的值是可以显示的ASCII值......