【文章內(nèi)容簡介】
end process。 t8: process(clk,counter,rset,rst,choose,tmp) ROM地址控制輸出進程 begin if rst=39。139。 then tmp=000000000。 elsif rset=39。139。 then tmp=000000000。 elsif tmp=127 then tmp =000000000。 elsif (clk39。event and clk=39。139。) if then en=39。039。 then tmp=tmp+1。 end if。 end if。 case choose is when 00 = counter=tmp。 when 01 = counter=tmp+128。 when 10 = counter=tmp+256。 when 11 = counter=tmp+385。 when others = counter=000000000。 end case。 end process。 u1:music port map(address=counter,q=toneindex,inclock=clk)。end。 程序的功能是通過按鍵選取要播放的樂曲,在每到來一個時鐘時,當復位鍵clk和暫停鍵en沒有按下時,地址值address遞增1,把選中的樂曲在LPM_ROM地址上所存儲的音符連續(xù)數(shù)據(jù)輸出。當復位鍵clk按下時,停止播放樂曲,再次按下復位鍵clk,重新輸出當前樂曲音符;當暫停鍵en按下時,停止播放樂曲,再次按下暫停鍵en,從暫停處開始輸出當前樂曲的音符; 分頻預置數(shù)模塊的VHDL語言設計分頻預置數(shù)模塊是樂曲簡譜碼對應的分頻預置數(shù)查表電路。它提供了每個音符所對應的分頻預置數(shù),即給數(shù)控分頻模塊提供計數(shù)初值,以“揮著翅膀的女孩”,“菊花臺”,“兩只老虎”,“世上只有媽媽好”等四首樂曲為例,列出了在這個樂曲中所用到的21個音符的分頻預置數(shù)。表1是音符頻率及其對應的預置數(shù)表1音符頻率及其對應的預置數(shù)音階頻率頻率設定數(shù) 預置數(shù)音階頻率頻率設定數(shù)預置數(shù)低74152891 101101001011 中35543193 110001111001 低63702745 101010111000 中24933082 110000001001 低53292576 101000010000 中14402960 101110001111 低42932390 100101010101 高716613795 111011010010 低32772291 100011110010 高614793758 111010101101 低22462063 100000001111 高513183717 111010000100 低12201823 11100011111 高411743670 111001010110 中78303494 110110100101 高311083645 111000111100 中67403420 110101011100 高29873589 111000000101 中56593337 110100001001 高18803528 110111000111 中45873244 110010101100 0音0 4095111111111111在這個模塊的VHDL邏輯描述中設置了以“揮著翅膀的女孩”,“菊花臺”,“兩只老虎”,“世上只有媽媽好”等四首樂曲的全部音符所對應的分頻預置數(shù),共21個,每一音符的停留時間由音樂節(jié)拍和地址發(fā)生器模塊的時鐘(Clk)的輸入頻率決定,在此為4Hz。這21個值的輸出由程序的5位輸入值index[4..0]確定。輸向分頻預置數(shù)模塊的程序中index[4..0]的值又由地址發(fā)生器模塊的輸出toneindex[4..0]的輸出值和持續(xù)時間決定。程序如下:library ieee。 use 。 entity tonetaba is port(index:in std_logic_vector (4 downto 0)。 code:out std_logic_vector(3 downto 0)。 high0:out std_logic_vector(2 downto 0)。 tone:out std_logic_vector(11 downto 0))。 end。 architecture one of tonetaba is begin search:process(index) begin case index is when00000=tone=111111111111。code=0000。high0=000。0/4095 when00001=tone=011100011111。code=0001。high0=001。L1/1823 when00010=tone=100000001111。code=0010。high0=001。L2/2063 when00011=tone=100011110010。code=0011。high0=001。L3/2291 when00100=tone=100101010101。code=0100。high0=001。L4/2390 when00101=tone=101000010000。code=0101。high0=001。L5/2576 when00110=tone=101010111000。code=0110。high0=001。L6/2745 when00111=tone=101101001011。code=0111。high0=001。L7/2891 when01000=tone=101110001111。code=0001。high0=010。M1/2960 when01001=tone=110000001001。code=0010。high0=010。M2/3082 when01010=tone=110001111001。code=0011。high0=010。M3/3193 when01011=tone=110010101100。code=0100。high0=010。M4/3244 when01100=tone=110100001001。code=0101。high0=010。M5/3337 when01101=tone=110101011100。code=0110。high0=010。M6/3420 when01110=tone=110110100101。code=0111。high0=010。M7/34