libraryIEEE;useIEEE.STD_LOGIC_1164.all;useieee.std_logic_arith.all;useIEEE.STD_LOGIC_UNSIGNED.ALL;entityzuoyeisPORT(clk:INSTD_LOGIC;--时钟信号led:outstd_logic;--亮灯信号num2:INSTD_LOGIC;--频率选定num1:INSTD_LOGIC;--波形选择smg:outstd_logic_vector(6downto0);--数码管的段数据smgkz:outstd_logic_vector(3downto0);--数码管的选通信号pwm_out:outstd_logic);ENDzuoye;architectureboxingofzuoyeissignalk:integerrange0to3;signalm:integerrange1to3:=1;signalclk1k,clk1:std_logic;signalcount:integerrange1to25000:=1;signalkey3filt:std_logic;--按键change消抖后得到的信号signalkey3cnt:integerrange0to50000000;--用于对yiwei按键输入有效时间进行计数signalkey4filt:std_logic;--按键yiwei消抖后得到的信号signalkey4cnt:integerrange0to50000000;--用于对CHANGE按键输入有效时间进行计数signalpin:integerrange1to3:=1;signalcounta,countb,countc,countd,counte,countf,countg,counth,counti:integerrange0to50000000;signalcounta1,countb1,countc1,countd1,counte1,countf1,countg1,counth1,counti1:integerrange0to50000000;signalout1,out2,out3,out4,out5,out6,out7,out8,out9:std_logic;signalaa,ab,ac:integer:=0;signalc1,c2,c3:integerrange0to50000000;--按键消抖Beginprocess(num1)---num1constantN:integer:=5000000;beginifclk'eventandclk='1'thenifnum1='0'then--当key1输入低电平,即按键按下ifkey3cnt/=Nthen--一直计数到Nkey3cnt=key3cnt+1;endif;ifkey3cnt=N-1then--最后一个计数时输出key1filt脉冲key3filt='1';elsekey3filt='0';endif;elsekey3cnt=0;endif;endif;endprocess;process(num2)---num2——消抖constantN:integer:=5000000;beginifclk'eventandclk='1'thenifnum2='0'thenifkey4cnt/=Nthenkey4cnt=key4cnt+1;endif;ifkey4cnt=N-1thenkey4filt='1';elsekey4filt='0';endif;elsekey4cnt=0;endif;endif;endprocess;process(clk)beginif(clk'eventandclk='1')thenifcount=25000thenclk1k=notclk1k;count=1;elsecount=count+1;endif;endif;endprocess;process(clk1k)——数码管动态显示beginif(clk1k'eventandclk1k='1')thenif(k=3)thenk=0;elsek=k+1;endif;endif;casekiswhen0=smgkz=0111;when1=smgkz=1011;when2=smgkz=1101;when3=smgkz=1110;endcase;endprocess;process(clk,key3filt)——波形选择beginif(clk'eventandclk='1')thenif(key3filt='1')thenifm=3thenm=1;elsem=m+1;endif;endif;endif;endprocess;process(clk,key4filt)——选择波形频率beginif(clk'eventandclk='1')thenif(key4filt='1')thenifpin=3thenpin=1;elsepin=pin+1;endif;endif;endif;endprocess;process(clk)——第一个三角波函数beginifrising_edge(clk)thenifaa=0thenifcounta1000-counta1thenout1='0';elseout1='1';endif;ifcounta=1000thencounta=0;ifcounta1=1000thenaa=1;elsecounta1=counta1+1;endif;elsecounta=counta+1;endif;elsifaa=1thenifcounta1000-counta1thenout1='0';elseout1='1';endif;ifcounta=1000thencounta=0;ifcounta1=0thenaa=0;elsecounta1=counta1-1;endif;elsecounta=counta+1;endif;endif;endif;endprocess;process(clk)——第二个三角波函数beginifrising_edge(clk)thenifab=0thenifcountb2000-countb1thenout2='0';elseout2='1';endif;ifcountb=2000thencountb=0;ifcountb1=2000thenab=1;elsecountb1=countb1+1;endif;elsecountb=countb+1;endif;elsifab=1thenifcountb2000-countb1thenout2='0';elseout2='1';endif;ifcountb=2000thencountb=0;ifcountb1=0thenab=0;elsecountb1=countb1-1;endif;elsecountb=countb+1;endif;endif;endif;endprocess;process(clk)——第三个三角波函数beginifrising_edge(clk)thenifac=0thenifcountg500-countg1thenout7='0';elseout7='1';endif;ifcountg=500thencountg=0;ifcountg1=500thenac=1;elsecountg1=countg1+1;endif;elsecountg=countg+1;endif;elsifac=1thenifcountg500-countg1thenout7='0';elseout7='1';endif;ifcountg=500thencountg=0;ifcountg1=0thenac=0;elsecountg1=countg1-1;endif;elsecountg=countg+1;endif;endif;endif;endprocess;process(clk)——第一个正弦函数variablea:integerrange0to50000000;variableb:integerrange0to50000000:=8;beginifrising_edge(clk)thenifcountc=2100thencountc=0;ifc1=0thenifa=31thenc1=1;elsea:=a+1;endif;endif;ifc1=1thenifa=1thenc1=0;elsea:=a-1;endif;endif;ifcountc1=2100thencountc1=0;elsecaseaiswhen1=countc1=1*b;when2=countc1=4*b;when4=countc1=13*b;when3=countc1=8*b;when5=countc1=19*b;when6=countc1=26*b;when7=countc1=34*b;when8=countc1=43*b;when9=countc1=53*b;when10=countc1=64*b;when11=countc1=75*b;when12=countc1=87*b;when13=countc1=99*b;when14=countc1=112*b;when15=countc1=124*b;when16=countc1=137*b;when17=countc1=150*b;when18=countc1=162*b;when19=countc1=174*b;when20=countc1=186*b;when21=countc1=197*b;when22=countc1=207*b;when23=countc1=217*b;when24=countc1=225*b;when25=countc1=233*b;when26=countc1=239*b;when27=countc1=245*b;when28=countc1=249*b;when29=countc1=252*b;when30=countc1=254*b;whenothers=countc1=255*b;endcase;endif;elsecountc=countc+1;endif;ifcountccountc1thenout3='1';elseout3='0';endif;endif;endprocess;process(clk)——第二个正弦函数variablea:integerrange0to50000000;variableb:integerrange0to50000000:=8;beginifrising_edge(clk)thenifcountd=3000thencountd=0;ifc2=0thenifa=31thenc2=1;elsea:=a+1;endif;endif;ifc2=1thenifa=1thenc2=0;elsea:=a-1;endif;endif;ifcountd1=3000thencountd1=0;elsecaseaiswhen1=countd1=1*b;when2=countd1=4*b;when4=countd1=13*b;when3=countd1=8*b;when5=countd1=19*b;when6=countd1=26*b;when7=countd1=34*b;when8=countd1=43*b;when9=countd1=53*b;when10=countd1=64*b;when11=countd1=75*b;when12=countd1=8