📄 df.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity dianziqin is
port ( clk32m : in std_logic;
keyin : in std_logic_vector(7 downto 0);
ledoutduan : out std_logic_vector(7 downto 0);
ledoutwei : out std_logic_vector(1 downto 0);
soundout : out std_logic );
end;
architecture behav of dianziqin is
signal fullspk,fullkeydelay : std_logic;
signal tonef : integer range 0 to 16#ffff#;--std_logic_vector(15 downto 0);
--signal ledoutduan : std_logic_vector(7 downto 0);
begin
divclk_tone: process(clk32m) --音调分频;
variable count16 : integer range 0 to 61162;--std_logic_vector(15 downto 0);
begin
if clk32m'event and clk32m='1' then count16:=count16+1;
if count16<tonef/2 then fullspk<='1';
elsif count16<tonef then fullspk<='0';
else count16:=0; fullspk<='0';
end if;
end if;
end process;
speakplay: process(fullspk) --音调波形输出
variable count1 : std_logic;
begin
if fullspk'event and fullspk='1' then count1:=not count1;
if count1='1' then soundout<='1';
else soundout<='0';
end if;
end if;
end process;
divclk_key: process(clk32m) --键盘扫描频率0.2s
variable count24 : integer range 0 to 8000000;--std_logic_vector(23 downto 0);
begin
if clk32m'event and clk32m='1' then count24:=count24+1;
if count24<4000000 then fullkeydelay<='1';
elsif count24<8000000 then fullkeydelay<='0';
else count24:=0;fullkeydelay<='0';
end if;
end if;
end process;
toneled: process(fullkeydelay,keyin) --产生音调值,数码显示;
begin
if fullkeydelay'event and fullkeydelay='1' then
if keyin(7)='1' and keyin(6)='1' then --高音
case keyin is
when "00000001" => tonef<=32395; ledoutduan<="11000001";
when "00000010" => tonef<=36364; ledoutduan<="11000010";
when "00000100" => tonef<=40816; ledoutduan<="11000011";
when "00001000" => tonef<=45819; ledoutduan<="11000100";
when "00010000" => tonef<=48544; ledoutduan<="11000101";
when "00100000" => tonef<=54477; ledoutduan<="11000110";
when "01000000" => tonef<=61162; ledoutduan<="11000111";
when others => null;
end case;
end if;
elsif keyin(7)='1' and keyin(5)='1' then --中音
case keyin is
when "00000001" => tonef<=30575; ledoutduan<="11010001";
when "00000010" => tonef<=27243; ledoutduan<="11010010";
when "00000100" => tonef<=24268; ledoutduan<="11010011";
when "00001000" => tonef<=22906; ledoutduan<="11010100";
when "00010000" => tonef<=20408; ledoutduan<="11010101";
when "00100000" => tonef<=18182; ledoutduan<="11010110";
when "01000000" => tonef<=16197; ledoutduan<="11010111";
when "10000000" => tonef<=15304; ledoutduan<="11011000";
when others => null;
end case;
elsif keyin(6)='1' and keyin(5)='1' then --低音
case keyin is
when "00000001" => tonef<=13620; ledoutduan<="11100001";
when "00000010" => tonef<=12135; ledoutduan<="11100010";
when "00000100" => tonef<=11454; ledoutduan<="11100011";
when "00001000" => tonef<=10204; ledoutduan<="11100100";
when "00010000" => tonef<=9091; ledoutduan<="11100101";
when "00100000" => tonef<=8099; ledoutduan<="11100110";
when others => null;
end case;
end if;
end process;
ledoutwei<="11";
--ledoutduan<=ledoutduan;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -