⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 top.vhd

📁 一个music的VHDL语言相当有用
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity musicdec is
    Port ( tonecode : in std_logic_vector(7 downto 0);
           tonestep : out std_logic_vector(9 downto 0));
end musicdec;

architecture Behavioral of musicdec is

begin

process(tonecode)
begin
case tonecode is
  when x"00" => tonestep<="00" & x"00";   --
  when x"01" => tonestep<="00" & x"58";   --1高音1
  when x"02" => tonestep<="00" & x"63";   --2高音1
  when x"03" => tonestep<="00" & x"6f";   --3高音1
  when x"04" => tonestep<="00" & x"75";
  when x"05" => tonestep<="00" & x"84";
  when x"06" => tonestep<="00" & x"94";
  when x"07" => tonestep<="00" & x"a6";
  when x"08" => tonestep<="00" & x"b0";
  when x"09" => tonestep<="00" & x"c5";
  when x"0a" => tonestep<="00" & x"dd";
  when x"0b" => tonestep<="00" & x"ea";
  when x"0c" => tonestep<="01" & x"07";
  when x"0d" => tonestep<="01" & x"27";
  when x"0e" => tonestep<="01" & x"4b";
  when x"0f" => tonestep<="01" & x"5f";	
  when x"10" => tonestep<="01" & x"8a";
  when x"11" => tonestep<="01" & x"ba";
  when x"12" => tonestep<="01" & x"d5";
  when x"13" => tonestep<="10" & x"0e";
  when x"14" => tonestep<="10" & x"4f";
  when x"15" => tonestep<="10" & x"97";
  when others => tonestep<="00" & x"00";
end case;
end process;

end Behavioral;




library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

--  Uncomment the following lines to use the declarations that are
--  provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;

entity top is
    Port (sysclk:in std_logic;
	       reset_n : in std_logic;
	     --  line_sel : out std_logic_vector(3 downto 0);
	     --	 key_dct: in std_logic_vector(3 downto 0); 
			 
			 model : in std_logic_vector(1 downto 0);
			 spkout0:out std_logic;
			 spkout1:out std_logic);
end top;

architecture Behavioral of top is
signal addr:std_logic_vector(23 downto 0);
signal divclk_counter:integer range 0 to 24999999;
signal musicclk:std_logic;
signal musickeyshiftbuf:std_logic_vector(31 downto 0);
signal musicno:std_logic_vector(1 downto 0);


signal step:std_logic_vector(9 downto 0);
signal tonecode:std_logic_vector(7 downto 0);
signal tonestep:std_logic_vector(9 downto 0);
signal codeaddr1:integer range 0 to 256; 
signal codeaddr2:integer range 0 to 447; 
signal codeaddr3:integer range 0 to 495; 

--signal tonekey :std_logic_vector(4 downto 0);
--signal musickey: std_logic;

component musicdec is
Port ( tonecode : in std_logic_vector(7 downto 0);
       tonestep : out std_logic_vector(9 downto 0));
end component;

--type state is (idle,playtone,playmusic);
--signal prestate:state;
--signal key : std_logic_vector(15 downto 0);



type datatype1 is array (0 to 255) of std_logic_vector(7 downto 0);
--music:two tigers
constant music1 : datatype1 :=(x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"00",
						x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0b",x"0b",x"0b",x"0b",x"0b",x"0b",x"0b",x"0b",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0b",x"0b",x"0b",x"0b",x"0b",x"0b",x"0b",x"0b",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"00",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0d",x"0d",x"0d",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0b",x"0b",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0d",x"0d",x"0d",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0b",x"0b",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"00",
						x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",
						x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"00",
						x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",
						x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"00");

type datatype2 is array (0 to 447) of std_logic_vector(7 downto 0);
--music:mother's kiss
constant music2 : datatype2 :=(
						x"08",x"08",x"08",x"08",x"08",x"08",x"09",x"09",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"09",x"09",
						x"08",x"08",x"08",x"08",x"08",x"08",x"06",x"06",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",
						x"08",x"08",x"08",x"08",x"00",x"00",x"09",x"09",x"0a",x"0a",x"0a",x"0a",x"09",x"09",x"08",x"08",
						x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"08",x"08",x"08",x"08",x"00",x"00",x"09",x"09",x"0a",x"0a",x"0a",x"00",x"0a",x"00",x"09",x"09",
						x"09",x"09",x"09",x"09",x"09",x"09",x"08",x"08",x"06",x"06",x"06",x"06",x"00",x"00",x"06",x"06",
						x"09",x"09",x"09",x"09",x"00",x"00",x"08",x"08",x"08",x"08",x"08",x"08",x"06",x"06",x"06",x"06",
						x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"00",
						x"05",x"05",x"05",x"05",x"06",x"00",x"06",x"00",x"08",x"08",x"08",x"00",x"08",x"08",x"08",x"00",
						x"09",x"09",x"09",x"00",x"09",x"09",x"08",x"08",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",
						x"09",x"09",x"09",x"09",x"00",x"00",x"0a",x"0a",x"09",x"09",x"09",x"09",x"08",x"08",x"08",x"08",
						x"08",x"08",x"09",x"08",x"06",x"06",x"05",x"05",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",
						x"05",x"05",x"05",x"05",x"00",x"00",x"06",x"06",x"08",x"08",x"08",x"08",x"09",x"09",x"0a",x"0a",
						x"0c",x"0c",x"0c",x"0c",x"09",x"09",x"0a",x"0a",x"08",x"08",x"09",x"08",x"06",x"06",x"06",x"06",
						x"06",x"06",x"06",x"06",x"09",x"09",x"09",x"09",x"07",x"07",x"07",x"07",x"06",x"06",x"05",x"05",
						x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",
						x"0c",x"00",x"0c",x"0c",x"0c",x"00",x"0c",x"00",x"0c",x"0c",x"0c",x"0c",x"0a",x"0a",x"0c",x"0c",
						x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0c",x"0c",x"0a",x"0a",x"0a",x"0a",
						x"0d",x"00",x"0d",x"00",x"0d",x"00",x"0d",x"00",x"0d",x"0d",x"0c",x"0c",x"0c",x"0c",x"0a",x"0a",
						x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"0d",x"0d",x"0d",x"0d",x"0c",x"0c",x"0d",x"0d",x"0c",x"0c",x"0c",x"0c",x"0a",x"0a",x"0a",x"0a",
						x"09",x"09",x"0a",x"0a",x"09",x"09",x"08",x"08",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",
						x"09",x"00",x"09",x"00",x"09",x"00",x"09",x"00",x"08",x"08",x"08",x"08",x"06",x"06",x"06",x"06",
						x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",
						x"0d",x"0d",x"0d",x"0d",x"0c",x"0c",x"0d",x"0d",x"0c",x"0c",x"0c",x"0c",x"0a",x"0a",x"0a",x"0a",
						x"09",x"09",x"0a",x"0a",x"09",x"09",x"08",x"08",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",
						x"09",x"00",x"09",x"00",x"09",x"00",x"09",x"00",x"08",x"08",x"08",x"08",x"06",x"06",x"06",x"06",
						x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05",x"05");


type datatype3 is array (0 to 495) of std_logic_vector(7 downto 0);
--music3:let's boat...
constant music3 : datatype3 :=(
						x"00",x"00",x"00",x"00",x"06",x"06",x"06",x"06",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"00",x"00",x"00",x"00",x"0c",x"0c",x"0c",x"0c",
						x"0a",x"0a",x"0a",x"0a",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",
						x"00",x"00",x"00",x"00",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",x"0a",x"0a",x"0a",x"0a",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"00",x"00",x"00",x"00",x"0c",x"0c",x"0c",x"0c",
						x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"00",x"0a",x"0a",x"0a",x"0a",x"0c",x"0c",x"0c",x"0c",
						x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"00",x"00",x"00",x"00",x"0d",x"0d",x"0d",x"0d",
						x"0f",x"0f",x"0f",x"0f",x"0e",x"0e",x"0d",x"0d",x"0c",x"0c",x"0c",x"0c",x"0d",x"0d",x"0d",x"0d",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"00",x"00",x"00",x"00",x"0c",x"0c",x"0c",x"0c",
						x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"08",x"06",x"06",x"06",x"06",x"06",x"06",x"06",x"06",
						x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",x"0a",x"0a",x"0a",x"0a",x"0d",x"0d",x"0d",x"0d",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",
						x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"0c",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",
						x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"00",x"00",x"00",x"00",x"0d",x"0d",x"0d",x"0d",
						x"0c",x"0c",x"0c",x"0c",x"0b",x"0b",x"0b",x"0b",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",
						x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"00",x"00",x"00",x"00",x"0c",x"0c",x"0c",x"0c",
						x"06",x"06",x"06",x"06",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",x"09",x"09",x"09",x"09",
						x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"08",x"08",x"08",x"08",x"09",x"09",x"09",x"09",
						x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0a",x"0c",x"0c",x"0c",x"0c",x"00",x"00",x"0c",x"0c",
						x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0f",x"0f",x"0f",x"0f",x"0f",x"0f",x"0f",x"0f",
						x"0e",x"0e",x"0e",x"0e",x"0d",x"0d",x"0d",x"0d",x"0c",x"0c",x"0c",x"0c",x"0a",x"0a",x"0a",x"0a",
						x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",
						x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",x"0d",
						x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00",x"00");


begin


U0:musicdec	port map(tonecode=>tonecode,tonestep=>tonestep);
spkout1<=addr(23);
spkout0<=addr(23);

step<=tonestep;

process(sysclk)
begin
  if sysclk'event and sysclk='1' then
    addr<=addr+step;             
	 if divclk_counter=1799999 then          --对50M进行分频得到musicclk大约为28HZ
	   musicclk<=not musicclk;
		divclk_counter<=0;
	 else
	   divclk_counter<=divclk_counter+1;
	 end if;

 --   musickeyshiftbuf<=musickey&musickeyshiftbuf(31 downto 1);
  --  if musickeyshiftbuf=x"00000001" then
  --    musicno<=musicno+1;
 --   end if;
  end if;
end process;

state_machine: process(musicclk)
begin
  if musicclk'event and musicclk='1' then
      		case model is
				  when "00" =>	tonecode<=music1(codeaddr1);
							if codeaddr1=255 then
						  	  codeaddr1<=0;
							else
						  	  codeaddr1<=codeaddr1+1;
							end if;
							codeaddr2<=0;
							codeaddr3<=0;
				  when "01" => tonecode<=music2(codeaddr2);
							if codeaddr2=447 then
						  	  codeaddr2<=0;
							else
						  	  codeaddr2<=codeaddr2+1;
							end if;
							codeaddr1<=0;
							codeaddr3<=0;
						   
				  when others => tonecode<=music3(codeaddr3);
							if codeaddr3=495 then
						  	  codeaddr3<=0;
							else
						  	  codeaddr3<=codeaddr3+1;
							end if;
							codeaddr2<=0;
							codeaddr1<=0;
				 -- when others=>

				end case;
  end if;                  
end process;

end Behavioral;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -