资源预览内容
第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
亲,该文档总共6页全部预览完了,如果喜欢就下载吧!
资源描述
附录程序清单:顶层模块程序:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity top isPort ( clk32MHz :in std_logic; -32MHz系统时钟 handTOauto : in std_logic; -键盘输入/自动演奏 code1 :out std_logic_vector(6 downto 0); -音符显示信号 index1 :in std_logic_vector(7 downto 0); -键盘输入信号 high1 :out std_logic; -高低音节信号 spkout :out std_logic); -音频信号end top;architecture Behavioral of top iscomponent automusic Port ( clk :in std_logic; Auto: in std_logic; index2:in std_logic_vector(7 downto 0); index0 : out std_logic_vector(7 downto 0); end component;component tone Port ( index : in std_logic_vector(7 downto 0); code : out std_logic_vector(6 downto 0); high : out std_logic; tone0 : out integer range 0 to 2047);end component;component speaker Port ( clk1 : in std_logic; tone1 : in integer range 0 to 2047; spks : out std_logic);end component;signal tone2: integer range 0 to 2047;signal indx:std_logic_vector(7 downto 0);begin u0:automusic port map(clk=clk32MHZ,index2=index1,index0=indx,Auto=handtoAuto); u1: tone port map(index=indx,tone0=tone2,code=code1,high=high1); u2: speaker port map(clk1=clk32MHZ,tone1=tone2,spks=spkout);end Behavioral;自动演奏模块程序library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity automusic isPort ( clk,Auto : in std_logic; -系统时钟;键盘输入/自动演奏index2 : in std_logic_vector(7 downto 0); -键盘输入信号index0 : out std_logic_vector(7 downto 0);-音符信号输出end automusic;architecture Behavioral of automusic issignal count0:integer range 0 to 31;-changesignal clk2:std_logic;beginpulse0:process(clk,Auto) -此进程完成对系统时钟8M的分频,得到4Hz的信号clk2variable count:integer range 0 to 8000000;begin if Auto=1 then count:=0;clk2=0; elsif clkevent and clk=1then count:=count+1; if count=4000000 then clk2=1; elsif count=8000000 then clk2=0;count:=0; end if; end if;end process;music:process(clk2) -此进程完成自动演奏部分曲的地址累加begin if clk2event and clk2=1 then if count0=31 then count0=0; else count0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 index0 null; end case;else index0 tone0=773;code=1001111;high tone0=912;code=0010010;high tone0=1036;code=0000110;high tone0=1116;code=1001100;high tone0=1197;code=0100100;high tone0=1290;code=0100000;high=0;when 01000
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号