2013-04-12 46 views
0

我對VHDL相當陌生,並且作爲我的第一個項目,我創建了一個帶旋轉文本的20x7 LED顯示屏。現在所有在顯示屏上打印的STD_LOGIC_VECTOR都是手動設置的。vhdl字符串轉換爲字體5x7

我想知道是否有可能得到STD_LOGIC_VECTOR表示從字符串(或字符?)的行。我發現usable font,但我不知道從哪裏開始...

回答

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; 
+0

非常感謝。它現在可以正常工作。 :)這個項目的想法是向我的女朋友說「生日快樂,親愛的」,他今天慶祝了20年。如果你有興趣,你可以看看[link](http://www.youtube.com/watch?v=mqFPlLehDf4&feature=youtu.be)。它在捷克。如你所見,你救了我。謝謝,謝謝,謝謝! :) –

+0

總是樂意救一對夫婦;-) – baldyHDL

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中的位置。

+0

感謝您的諮詢! 假設我完成了這個font_array並且我有一個變量長度字符串(例如「hello」)。 問題是我必須爲7行中的每一行將行連接爲'h'(row0)和'e'(row0)和'l'(row0)和'l'(row0)和'o'(row0)在顯示器上,所以結果看起來像這樣[鏈接](http://img825.imageshack.us/img825/6585/80149f067b9441dd8dc3941.png) 在你的例子中,它看起來好像你想要連接所有向量的一個字符,但我需要連接每個字符的第一行,每個字符的第二行等。 也有辦法做到這一點的功能? –

+0

我想我之前被誤解了...我更新了我的答案! – baldyHDL

+0

謝謝!這幫了我很多! :) –