【正文】
: in std_logic。 q : out std_logic_vector(4 downto 0))。 end ponent。 聲明 ROM 模塊 signal counter: std_logic_vector(8 downto 0)。地址發(fā)生器, 512 位 signal tone :std_logic_vector(4 downto 0)。 輸出音符 signal temp :std_logic_vector(1 downto 0)。 begin t8 : process(clk) begin temp = song amp。 back。輸入狀態(tài) if (clk39。event and clk = 39。139。) then case temp is when 00= counter = counter+1。if counter(8)= 39。139。 then counter=000000000。end if。 when 01= counter = counter1。if counter(8)= 39。139。 then counter=011111111。end if。 when 10= counter = counter+1。if counter(8)= 39。039。 then counter=100000000。end if。 when 11= counter = counter1。if counter(8)= 39。039。 then counter=111111111。end if。 when others=null。判斷最高位,決定切換歌曲以及歌曲的循環(huán) end case。 end if。 end process。 decoder:process(tone)從 rom 取出數(shù)據(jù)進行譯碼,作為下一級的輸入 begin if auto = 39。139。 then判斷自動 /手動模式 if pause =39。139。 then Toneindex=conv_std_logic_vector(2047,11)。判斷暫停,阻止暫停時的噪聲 else case conv_integer(tone) is 基于 FPGA 的電子琴設計 21 when 1 = Toneindex=conv_std_logic_vector(612,11)。 when 2 = Toneindex=conv_std_logic_vector(770,11)。 when 3 = Toneindex=conv_std_logic_vector(909,11)。 when 4 = Toneindex=conv_std_logic_vector(973,11)。 when 5 = Toneindex=conv_std_logic_vector(1090,11)。 when 6 = Toneindex=conv_std_logic_vector(1195,11)。 when 7 = Toneindex=conv_std_logic_vector(1288,11)。 when 11 = Toneindex=conv_std_logic_vector(1342,11)。 when 12 = Toneindex=conv_std_logic_vector(1409,11)。 when 13 = Toneindex=conv_std_logic_vector(1478,11)。 when 14 = Toneindex=conv_std_logic_vector(1510,11)。 when 15 = Toneindex=conv_std_logic_vector(1569,11)。 when 16 = Toneindex=conv_std_logic_vector(1621,11)。 when 17 = Toneindex=conv_std_logic_vector(1667,11)。 when 21 = Toneindex=conv_std_logic_vector(1689,11)。 when 22 = Toneindex=conv_std_logic_vector(1728,11)。 when 23 = Toneindex=conv_std_logic_vector(1763,11)。 when 24 = Toneindex=conv_std_logic_vector(1779,11)。 when 25 = Toneindex=conv_std_logic_vector(1808,11)。 when 26 = Toneindex=conv_std_logic_vector(1834,11)。 when 27 = Toneindex=conv_std_logic_vector(1857,11)。 when others=Toneindex=conv_std_logic_vector(2047,11)。 end case。 end if。譯碼, Toneindex 為分頻 器的初值 else Toneindex =ZZZZZZZZZZZ。如果為手動模式,則讓出總線的控制權(quán) end if。 end process。 u1:rom port map(address = counter,q=tone,inclock=clk)。 end。 數(shù)碼管譯碼模塊 library ieee。 use 。 use 。 USE 。 entity decoder is 沈陽工程學院課程設計 22 port( tone_code:in std_logic_vector(10 downto 0)。 D1:out std_logic_vector(3 downto 0)。 D0:out std_logic_vector(3 downto 0))。 end entity。 architecture one of decoder is begin process(tone_code) begin case conv_integer(tone_code) is when 612 = D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(1,4)。 when 770 = D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(2,4)。 when 909 = D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(3,4)。 when 973 = D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(4,4)。 when 1090 = D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(5,4)。 when 1195 = D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(6,4)。 when 1288 = D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(7,4)。 when 1342 = D1=conv_std_logic_vector(1,4)。D0=conv_std_logic_vector(1,4)。 when 1409 = D1=conv_std_logic_vector(1,4)。D0=conv_std_logic_vector(2,4)。 when 1478 = D1=conv_std_logic_vector(1,4)。D0=conv_std_logic_vector(3,4)。 when 1510 = D1=conv_std_logic_vector(1,4)。D0=conv_std_logic_vector(4,4)。 when 1569 = D1=conv_std_logic_vector(1,4)。D0=conv_std_logic_vector(5,4)。 when 1621 = D1=conv_std_logic_vector(1,4)。D0=conv_std_logic_vector(6,4)。 when 1667 = D1=conv_std_logic_vector(1,4)。D0=conv_std_logic_vector(7,4)。 when 1689 = D1=conv_std_logic_vector(2,4)。D0=conv_std_logic_vector(1,4)。 when 1728 = D1=conv_std_logic_vector(2,4)。D0=conv_std_logic_vector(2,4)。 when 1763 = D1=conv_std_logic_vector(2,4)。D0=conv_std_logic_vector(3,4)。 when 1779 = D1=conv_std_logic_vector(2,4)。D0=conv_std_logic_vector(4,4)。 when 1808 = D1=conv_std_logic_vector(2,4)。D0=conv_std_logic_vector(5,4)。 when 1834 = D1=conv_std_logic_vector(2,4)。D0=conv_std_logic_vector(6,4)。 when 1857 = D1=conv_std_logic_vector(2,4)。D0=conv_std_logic_vector(7,4)。 when others =D1=conv_std_logic_vector(0,4)。D0=conv_std_logic_vector(0,4)。 end case。 end process。 end one。