Speakera.vhd
资源名称:Music.rar [点击查看]
上传用户:jnxfc1
上传日期:2022-08-09
资源大小:363k
文件大小:10k
源码类别:
VHDL/FPGA/Verilog
开发平台:
Others
- ---------------------------------------------------------------------------------------------------
- --*************************************************************************************************
- -- CreateDate : 2007-07-24
- -- ModifData : 2007-07-24
- -- Description : Perform Music
- --
- -- Author : Explorer01
- -- Version : V1.0
- --*************************************************************************************************
- ---------------------------------------------------------------------------------------------------
- -- VHDL library Declarations
- LIBRARY IEEE;
- USE IEEE.std_logic_1164.ALL;
- USE IEEE.std_logic_unsigned.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- ---------------------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------------------
- -- The Entity Declarations
- ENTITY Speakera IS
- PORT
- (
- RESET: IN STD_LOGIC;
- CLK: IN STD_LOGIC; -- Period :
- CLK8Hz:IN STD_LOGIC; -- Period : 8Hz
- ToneOut : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
- BEEP : OUT STD_LOGIC
- );
- END Speakera;
- ---------------------------------------------------------------------------------------------------
- ---------------------------------------------------------------------------------------------------
- -- The Architecture of Entity Declarations
- ARCHITECTURE Speakera_arch OF Speakera IS
- ----------------------------
- SIGNAL ToneIndex : INTEGER RANGE 0 TO 15;
- SIGNAL CODE : INTEGER RANGE 0 TO 15;
- SIGNAL Tone : INTEGER RANGE 0 TO 16#7FF#;
- SIGNAL HIGH : STD_LOGIC;
- SIGNAL FullSpkS : STD_LOGIC;
- ----------------------------
- SIGNAL Counter : INTEGER RANGE 0 TO 138;
- BEGIN
- -------------------------------------------------
- --
- Search : PROCESS( ToneIndex )
- BEGIN
- -- Encoder, Controlling the Tone
- CASE ToneIndex IS
- WHEN 0 => Tone <= 2047; CODE <= 0; HIGH <= '0';
- WHEN 1 => Tone <= 773; CODE <= 1; HIGH <= '0';
- WHEN 2 => Tone <= 912; CODE <= 2; HIGH <= '0';
- WHEN 3 => Tone <= 1036; CODE <= 3; HIGH <= '0';
- WHEN 5 => Tone <= 1197; CODE <= 5; HIGH <= '0';
- WHEN 6 => Tone <= 1290; CODE <= 6; HIGH <= '0';
- WHEN 7 => Tone <= 1372; CODE <= 7; HIGH <= '0';
- WHEN 8 => Tone <= 1410; CODE <= 1; HIGH <= '1';
- WHEN 9 => Tone <= 1480; CODE <= 2; HIGH <= '1';
- WHEN 10 => Tone <= 1542; CODE <= 3; HIGH <= '1';
- WHEN 12 => Tone <= 1622; CODE <= 5; HIGH <= '1';
- WHEN 13 => Tone <= 1668; CODE <= 6; HIGH <= '1';
- WHEN 15 => Tone <= 1728; CODE <= 1; HIGH <= '1';
- WHEN OTHERS => NULL;
- END CASE;
- END PROCESS;
- ToneOut <= CONV_STD_LOGIC_VECTOR( CODE, 4 );
- -------------------------------------------------
- --
- GenSpkS : PROCESS( CLK, Tone )
- VARIABLE Count11 : INTEGER RANGE 0 TO 16#7FF#;
- BEGIN
- IF( CLK'EVENT AND CLK = '1' ) THEN
- IF( Count11 = 16#7FF# ) THEN
- Count11 := Tone;
- FullSpkS <= '1';
- ELSE
- Count11 := Count11 + 1;
- FullSpkS <= '0';
- END IF;
- END IF;
- END PROCESS;
- -------------------------------------------------
- --
- SpkOut : PROCESS( FullSpkS )
- VARIABLE Count2 : STD_LOGIC;
- VARIABLE SpkS : STD_LOGIC;
- BEGIN
- IF( FullSpkS'EVENT AND FullSpkS = '1' ) THEN
- Count2 := NOT Count2;
- IF( Count2 = '1' ) THEN SpkS := '1';
- ELSE SpkS := '0';
- END IF;
- END IF;
- BEEP <= SpkS;
- END PROCESS;
- -------------------------------------------------
- --
- PROCESS( CLK8Hz, Counter )
- BEGIN
- IF( Counter = 138 ) THEN Counter <= 0;
- ELSIF(CLK8Hz'EVENT AND CLK8Hz = '1') THEN
- Counter <= Counter + 1;
- END IF;
- CASE Counter IS
- WHEN 00 => ToneIndex <= 3; -- 简谱"3"音
- WHEN 01 => ToneIndex <= 3; -- 发4个时钟节拍
- WHEN 02 => ToneIndex <= 3;
- WHEN 03 => ToneIndex <= 3;
- WHEN 04 => ToneIndex <= 5; -- 简谱"5"音
- WHEN 05 => ToneIndex <= 5; -- 发3个时钟节拍
- WHEN 06 => ToneIndex <= 5;
- WHEN 07 => ToneIndex <= 6; -- 简谱"6"音
- WHEN 08 => ToneIndex <= 8;
- WHEN 09 => ToneIndex <= 8;
- WHEN 10 => ToneIndex <= 8;
- WHEN 11 => ToneIndex <= 9;
- WHEN 12 => ToneIndex <= 6;
- WHEN 13 => ToneIndex <= 8;
- WHEN 14 => ToneIndex <= 5;
- WHEN 15 => ToneIndex <= 5;
- WHEN 16 => ToneIndex <= 12;
- WHEN 17 => ToneIndex <= 12;
- WHEN 18 => ToneIndex <= 12;
- WHEN 19 => ToneIndex <= 15;
- WHEN 20 => ToneIndex <= 13;
- WHEN 21 => ToneIndex <= 12;
- WHEN 22 => ToneIndex <= 10;
- WHEN 23 => ToneIndex <= 12;
- WHEN 24 => ToneIndex <= 9;
- WHEN 25 => ToneIndex <= 9;
- WHEN 26 => ToneIndex <= 9;
- WHEN 27 => ToneIndex <= 9;
- WHEN 28 => ToneIndex <= 9;
- WHEN 29 => ToneIndex <= 9;
- WHEN 30 => ToneIndex <= 9;
- WHEN 31 => ToneIndex <= 0;
- WHEN 32 => ToneIndex <= 9;
- WHEN 33 => ToneIndex <= 9;
- WHEN 34 => ToneIndex <= 9;
- WHEN 35 => ToneIndex <= 10;
- WHEN 36 => ToneIndex <= 7;
- WHEN 37 => ToneIndex <= 7;
- WHEN 38 => ToneIndex <= 6;
- WHEN 39 => ToneIndex <= 6;
- WHEN 40 => ToneIndex <= 5;
- WHEN 41 => ToneIndex <= 5;
- WHEN 42 => ToneIndex <= 5;
- WHEN 43 => ToneIndex <= 6;
- WHEN 44 => ToneIndex <= 8;
- WHEN 45 => ToneIndex <= 8;
- WHEN 46 => ToneIndex <= 9;
- WHEN 47 => ToneIndex <= 9;
- WHEN 48 => ToneIndex <= 3;
- WHEN 49 => ToneIndex <= 3;
- WHEN 50 => ToneIndex <= 8;
- WHEN 51 => ToneIndex <= 8;
- WHEN 52 => ToneIndex <= 6;
- WHEN 53 => ToneIndex <= 5;
- WHEN 54 => ToneIndex <= 6;
- WHEN 55 => ToneIndex <= 8;
- WHEN 56 => ToneIndex <= 5;
- WHEN 57 => ToneIndex <= 5;
- WHEN 58 => ToneIndex <= 5;
- WHEN 59 => ToneIndex <= 5;
- WHEN 60 => ToneIndex <= 5;
- WHEN 61 => ToneIndex <= 5;
- WHEN 62 => ToneIndex <= 5;
- WHEN 63 => ToneIndex <= 5;
- WHEN 64 => ToneIndex <= 10;
- WHEN 65 => ToneIndex <= 10;
- WHEN 66 => ToneIndex <= 10;
- WHEN 67 => ToneIndex <= 12;
- WHEN 68 => ToneIndex <= 7;
- WHEN 69 => ToneIndex <= 7;
- WHEN 70 => ToneIndex <= 9;
- WHEN 71 => ToneIndex <= 9;
- WHEN 72 => ToneIndex <= 6;
- WHEN 73 => ToneIndex <= 8;
- WHEN 74 => ToneIndex <= 5;
- WHEN 75 => ToneIndex <= 5;
- WHEN 76 => ToneIndex <= 5;
- WHEN 77 => ToneIndex <= 5;
- WHEN 78 => ToneIndex <= 5;
- WHEN 79 => ToneIndex <= 5;
- WHEN 80 => ToneIndex <= 3;
- WHEN 81 => ToneIndex <= 5;
- WHEN 82 => ToneIndex <= 3;
- WHEN 83 => ToneIndex <= 3;
- WHEN 84 => ToneIndex <= 5;
- WHEN 85 => ToneIndex <= 6;
- WHEN 86 => ToneIndex <= 7;
- WHEN 87 => ToneIndex <= 9;
- WHEN 88 => ToneIndex <= 6;
- WHEN 89 => ToneIndex <= 6;
- WHEN 90 => ToneIndex <= 6;
- WHEN 91 => ToneIndex <= 6;
- WHEN 92 => ToneIndex <= 6;
- WHEN 93 => ToneIndex <= 6;
- WHEN 94 => ToneIndex <= 5;
- WHEN 95 => ToneIndex <= 6;
- WHEN 96 => ToneIndex <= 8;
- WHEN 97 => ToneIndex <= 8;
- WHEN 98 => ToneIndex <= 8;
- WHEN 99 => ToneIndex <= 9;
- WHEN 100 => ToneIndex <= 12;
- WHEN 101 => ToneIndex <= 12;
- WHEN 102 => ToneIndex <= 12;
- WHEN 103 => ToneIndex <= 10;
- WHEN 104 => ToneIndex <= 9;
- WHEN 105 => ToneIndex <= 9;
- WHEN 106 => ToneIndex <= 10;
- WHEN 107 => ToneIndex <= 9;
- WHEN 108 => ToneIndex <= 8;
- WHEN 109 => ToneIndex <= 8;
- WHEN 110 => ToneIndex <= 6;
- WHEN 111 => ToneIndex <= 5;
- WHEN 112 => ToneIndex <= 3;
- WHEN 113 => ToneIndex <= 3;
- WHEN 114 => ToneIndex <= 3;
- WHEN 115 => ToneIndex <= 3;
- WHEN 116 => ToneIndex <= 8;
- WHEN 117 => ToneIndex <= 8;
- WHEN 118 => ToneIndex <= 8;
- WHEN 119 => ToneIndex <= 8;
- WHEN 120 => ToneIndex <= 6;
- WHEN 121 => ToneIndex <= 8;
- WHEN 122 => ToneIndex <= 6;
- WHEN 123 => ToneIndex <= 5;
- WHEN 124 => ToneIndex <= 3;
- WHEN 125 => ToneIndex <= 5;
- WHEN 126 => ToneIndex <= 6;
- WHEN 127 => ToneIndex <= 8;
- WHEN 128 => ToneIndex <= 5;
- WHEN 129 => ToneIndex <= 5;
- WHEN 130 => ToneIndex <= 5;
- WHEN 131 => ToneIndex <= 5;
- WHEN 132 => ToneIndex <= 5;
- WHEN 133 => ToneIndex <= 5;
- WHEN 134 => ToneIndex <= 5;
- WHEN 135 => ToneIndex <= 5;
- -- 程序过长,部分省略
- WHEN 136 => ToneIndex <= 0; -- 简谱休止符à输出
- WHEN 137 => ToneIndex <= 0; -- 频率为零
- WHEN 138 => ToneIndex <= 0;
- WHEN OTHERS => ToneIndex <= 0;
- -- WHEN OTHERS => NULL;
- END CASE;
- END PROCESS;
- -------------------------------------------------
- -------------------------------------------------
- --
- END Speakera_arch;