锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

音乐音符的VHDL程序

时间:2024-05-17 08:37:10

一、以20M的时钟频率编写的高中低音符,每个音符响一秒钟(乐谱知识见后面文字部分介绍):
LIBRARY E;
USE IEEE.D_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
EITY music_act IS
PORT(CLK,rst:in std_logic;
out_bit:OUT STD_LOGIC);
END music_act;
ARCHICTURE PVJ OF music_act IS
SIGNAL time:STD_LOGIC_(24 NTO 0);
signal music21:STD_LOGIC_VECTOR(8 DOWNTO 0);
SIGNAL L1,L2,L3,L4,L5,L6,L7:STD_LOGIC_VECTOR(16 DOWNTO 0);
SIGNAL M1,M2,M3,M4,M5,M6,M7:STD_LOGIC_VECTOR(16 DOWNTO 0);
SIGNAL H1,H2,H3,H4,H5,H6,H7:STD_LOGIC_VECTOR(16 DOWNTO 0);
SIGNAL LL1,LL2,LL3,LL4,LL5,LL6,LL7,C:STD_LOGIC;
SIGNAL MM1,MM2,MM3,MM4,MM5,MM6,MM7:STD_LOGIC;
SIGNAL HH1,HH2,HH3,HH4,HH5,HH6,HH7,X0:STD_LOGIC;
BEGIN
process(clk,rst)
begin
X0<='1';
if clk'event and clk='1' then time<=time+1; --将20M频率6分频
if L1=76444 then L1<="00000000000000000";
else L1<=L1+1;
end if;
IF L1<38222 THEN LL1<='1';ELSE LL1<='0';END IF;
if L2=68104 then L2<="00000000000000000";
else L2<=L2+1;
end if;
IF L2<34052 THEN LL2<='1';ELSE LL2<='0';END IF;
if L3=60674 then L3<="00000000000000000";
else L3<=L3+1;
end if;
IF L3<30337 THEN LL3<='1';ELSE LL3<='0';END IF;
if L4=57268 then L4<="00000000000000000";
else L4<=L4+1;
end if;
IF L4<28634 THEN LL4<='1';ELSE LL4<='0';END IF;
if L5=51020 then L5<="00000000000000000";
else L5<=L5+1;
end if;
IF L5<25510 THEN LL5<='1';ELSE LL5<='0';END IF;
if L6=50000 then L6<="00000000000000000";
else L6<=L6+1;
end if;
IF L6<25000 THEN LL6<='1';ELSE LL6<='0';END IF;
if L7=40494 then L7<="00000000000000000";
else L7<=L7+1;
end if;
IF L7<20247 THEN LL7<='1';ELSE LL7<='0';END IF;
if M1=38222 then M1<="00000000000000000";
else M1<=M1+1;
end if;
IF M1<19111 THEN MM1<='1';ELSE MM1<='0';END IF;
if M2=34051 then M2<="00000000000000000";
else M2<=M2+1;
end if;
IF M2<17026 THEN MM2<='1';ELSE MM2<='0';END IF;
if M3=33036 then M3<="00000000000000000";
else M3<=M3+1;
end if;
IF M3<16518 THEN MM3<='1';ELSE MM3<='0';END IF;
if M4=28634 then M4<="00000000000000000";
else M4<=M4+1;
end if;
IF M4<14217 THEN MM4<='1';ELSE MM4<='0';END IF;
if M5=25510 then M5<="00000000000000000";
else M5<=M5+1;
end if;
IF M5<12755 THEN MM5<='1';ELSE MM5<='0';END IF;
if M6=25000 then M6<="00000000000000000";
else M6<=M6+1;
end if;
IF M6<12500 THEN MM6<='1';ELSE MM6<='0';END IF;
if M7=20247 then M7<="00000000000000000";
else M7<=M7+1;
end if;
IF M7<10124 THEN MM7<='1';ELSE MM7<='0';END IF;
if H1=19110 then H1<="00000000000000000";
else H1<=H1+1;
end if;
IF H1<9555 THEN HH1<='1';ELSE HH1<='0';END IF;
if H2=17025 then H2<="00000000000000000";
else H2<=H2+1;
end if;
IF H2<8513 THEN HH2<='1';ELSE HH2<='0';END IF;
if H3=15168 then H3<="00000000000000000";
else H3<=H3+1;
end if;
IF H3<7584 THEN HH3<='1';ELSE HH3<='0';END IF;
if H4=14316 then H4<="00000000000000000";
else H4<=H4+1;
end if;
IF H4<7158 THEN HH4<='1';ELSE HH4<='0';END IF;
if H5=12754 then H5<="00000000000000000";
else H5<=H5+1;
end if;
IF H5<6377 THEN HH5<='1';ELSE HH5<='0';END IF;
if H6=11764 then H6<="00000000000000000";
else H6<=H6+1;
end if;
IF H6<5882 THEN HH6<='1';ELSE HH6<='0';END IF;
if H7=10124 then H7<="00000000000000000";
else H7<=H7+1;
end if;
IF H7<5062 THEN HH7<='1';ELSE HH7<='0';END IF;
if time=2499999 then time<="0000000000000000000000000";c<='1';
else c<='0';
end if;
end if;
end process;
PROCESS(c,RST)
BEGIN
if c'event and c='1' then music21<=music21+1;
if music21=263 then music21<="000000000";
end if;
end if;--(国歌)
if music21>=0 and music21<=1 then out_bit<=LL5;END IF;
IF music21>=2 and music21<=5 then out_bit<=MM1;END IF;
IF music21>=6 and music21<=7 then out_bit<=MM1;END IF;
IF music21>=8 and music21<=10 then out_bit<=mm1;END IF;
IF music21=11 then out_bit<=MM1;END IF;
IF music21>=12 and music21<=14 then out_bit<=LL5;END IF;
IF music21=15 then out_bit<=LL6;END IF;
if music21=16 then out_bit<=LL7;END IF;
IF music21>=17 and music21<=20 then out_bit<=MM1;END IF;
IF music21>=21 and music21<=24 then out_bit<=MM1;END IF;
IF music21>=25 and music21<=26 then out_bit<=X0;END IF;
IF music21>=27 and music21<=28 then out_bit<=MM3;END IF;
IF music21>=29 and music21<=30 then out_bit<=MM1;END IF;
IF music21=31 then out_bit<=MM2;END IF;
if music21=32 then out_bit<=MM3;END IF;
IF music21>=33 and music21<=38 then out_bit<=MM5;END IF;
IF music21=39 then out_bit<=MM5;END IF;
IF music21>=40 and music21<=48 then out_bit<=MM5;END IF;
IF music21>=49 and music21<=53 then out_bit<=MM3;END IF;
IF music21>=54 and music21<=56 then out_bit<=MM1;END IF;
IF music21=57 then out_bit<=MM3;END IF;
IF music21>=58 and music21<=60 then out_bit<=MM5;END IF;
IF music21=61 then out_bit<=MM3;END IF;
IF music21>=62 and music21<=71 then out_bit<=MM2;END IF;
IF music21>=72 and music21<=75 then out_bit<=MM6;END IF;
IF music21>=76 and music21<=79 then out_bit<=MM5;END IF;
IF music21>=80 and music21<=83 then out_bit<=MM2;END IF;
IF music21>=84 and music21<=87 then out_bit<=MM3;END IF;
IF music21>=88 and music21<=89 then out_bit<=MM5;END IF;
IF music21>=90 and music21<=93 then out_bit<=MM3;END IF;
IF music21>=94 and music21<=95 then out_bit<=MM5;END IF;
IF music21>=96 and music21<=97 then out_bit<=MM3;END IF;
IF music21>=98 then out_bit<=MM2;END IF;
IF music21>=93 then out_bit<=MM3;END IF;
IF music21>=100 and music21<=102 then out_bit<=MM1;END IF;
IF music21>=103 then out_bit<=MM2;END IF;
IF music21>=104 and music21<=107 then out_bit<=MM3;END IF;
IF music21>=108 and music21<=111 then out_bit<=X0;END IF;
IF music21>=112 and music21<=114 then out_bit<=MM5;END IF;
IF music21=115 then out_bit<=LL6;END IF;
IF music21>=116 and music21<=119 then out_bit<=MM1;END IF;
IF music21>=120 and music21<=123 then out_bit<=MM3;END IF;
IF music21>=124 and music21<=127 then out_bit<=MM5;END IF;
IF music21>=128 and music21<=131 then out_bit<=MM2;END IF;
IF music21>=132 and music21<=135 then out_bit<=LL6;END IF;
IF music21>=136 and music21<=141 then out_bit<=MM2;END IF;
IF music21>=142 and music21<=143 then out_bit<=LL5;END IF;
IF music21>=144 and music21<=151 then out_bit<=MM1;END IF;
IF music21>=152 and music21<=159 then out_bit<=MM3;END IF;
IF music21>=160 and music21<=175 then out_bit<=MM5;END I

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章