0

我对 VHDL 很陌生,作为我的第一个项目,我创建了一个带有旋转文本的 20x7 LED 显示屏。现在所有STD_LOGIC_VECTOR打印在显示屏上的 s 都是手动设置的。

我想知道是否有可能STD_LOGIC_VECTOR从字符串(或字符?)中获取行的表示。我找到了可用的字体,但我不知道从哪里开始......

4

2 回答 2

1

要表示您的字体表,您可以使用数组和常量。见下面的例子:

    type font_array is array(0 to 127, 0 to 5) of std_logic_vector(7 downto 0);
    constant font: font_array :=(
       (X"01",X"02",X"03",X"04",X"05",X"06"), -- row 0
       (X"11",X"12",X"13",X"14",X"15",X"16"), -- row 1
       ...
       (X"11",X"12",X"13",X"14",X"15",X"16") -- last row 
    );

要获得一行你的角色,你可以使用一个函数。见例子:

    function get_font_row(char_pos, row: integer) return std_logic_vector is
        variable result: std_logic_vector(5 downto 0);
    begin
        for i in 0 to 5 loop
            result(i):=font(char_pos, i)(row);
        end loop;

        return result;
    end get_font_row;

这个字符行可以组合成一个 LED 行:

    led_row<=get_font_row(ch_h,n) & get_font_row(ch_a,n) & get_font_row(ch_l,n) & ...;

其中“n”是您的 LED 行号,“ch_h”、“ch_a”和“ch_l”是字体在 font_array 中的位置。

于 2013-04-12T06:06:01.640 回答
1

要实现您在后面的评论中要求的功能,您首先需要一个翻译函数 char2int 来寻址您的数组。例子:

    function char2int (chr: character) return integer is
        variable i: integer;
    begin
        case chr is
        when 'H' => i:=0;
        when 'A' => i:=1;
        when 'L' => i:=2;
        when 'O' => i:=3;
        when others => i:=4;
        end case;

        return i;
    end char2int;

那么主要功能就像您在 C 示例中所建议的那样:

    function string_to_bitfile(constant txt_str: string) return text_type is
        variable txt: text_type;
    begin
        for i in 0 to (txt_str'length-1) loop
            for j in 0 to 5 loop
                txt(6*i+j):=font(char2int(txt_str(i)),j);
            end loop;
        end loop;

        return txt;
    end string_to_bitfile;
于 2013-04-16T06:17:56.917 回答