将整数值转换为 ASCII 字符 - VHDL
convert integer values to ASCII characters - VHDL
我需要在 2x16 显示器上显示一些整数值,但显示器只能识别 ASCII 字符。因此,在我向显示器发送一些值之前,我需要将其转换为字符串...有什么想法吗?
非常感谢!
也许 table 查找会有用。将 ASCII 字符存储在某处,并使用一种方法将 ASCII 映射到您的 "Integer." 我想您使用的是标准 INTEGER 类型?无论哪种方式,它当前使用的格式应该能够以某种方式映射到 ASCII(如果尚未映射)。
有办法做到这一点。所以一开始你需要将整数转换为 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值...
我需要在 2x16 显示器上显示一些整数值,但显示器只能识别 ASCII 字符。因此,在我向显示器发送一些值之前,我需要将其转换为字符串...有什么想法吗?
非常感谢!
也许 table 查找会有用。将 ASCII 字符存储在某处,并使用一种方法将 ASCII 映射到您的 "Integer." 我想您使用的是标准 INTEGER 类型?无论哪种方式,它当前使用的格式应该能够以某种方式映射到 ASCII(如果尚未映射)。
有办法做到这一点。所以一开始你需要将整数转换为 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值...