📄 music_player.vhd
字号:
--Music Player
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity Music_Player is
port(clk_2MHz : in std_logic;
scale : in integer range 0 to 21; --a rest and musical scale from low 1 to high 7
tune : out std_logic); --output the tune of the music
end Music_Player;
architecture rtl of Music_Player is
signal count : integer range 0 to 3822 :=0;
signal flag,feq: std_logic;
begin
process(clk_2MHz,scale)
begin
if clk_2MHz'event and clk_2MHz='1' then
if scale=0 then flag<='0'; --rest
else
count<=count+1;
if scale=1 then --low 1
if count<3822 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=2 then --low 2
if count<3405 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=3 then --low 3
if count<3034 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=4 then --low 4
if count<2863 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=5 then --low 5
if count<2551 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=6 then --low 6
if count<2273 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=7 then --low 7
if count<2025 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=8 then --middle 1
if count<1911 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=9 then --middle 2
if count<1703 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=10 then --middle 3
if count<1517 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=11 then --middle 4
if count<1432 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=12 then --middle 5
if count<1276 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=13 then --middle 6
if count<1136 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=14 then --middle 7
if count<1012 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=15 then --high 1
if count<956 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=16 then --high 2
if count<851 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=17 then --high 3
if count<758 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=18 then --high 4
if count<716 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=19 then --high 5
if count<638 then flag<='0';
else flag<='1'; count<=0;
end if;
elsif scale=20 then --high 6
if count<568 then flag<='0';
else flag<='1'; count<=0;
end if;
else --high 7
if count<506 then flag<='0';
else flag<='1'; count<=0;
end if;
end if;
end if;
end if;
end process;
process(flag)
begin
if flag'event and flag='1' then
feq<=not feq; --freqency of the audio
end if;
tune<=feq;
end process;
end rtl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -