欢迎来到天天文库
浏览记录
ID:31819717
大小:74.34 KB
页数:10页
时间:2019-01-18
《【vhdl程序举例大全-基本语法】》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、[VHDL程序举例大全-基本语法】计数器:std_logic_unsigned的用法--Thisexampleshowstheuseofthepackage'std_logic_unsigncd,・--Theminusoperator'-isoverloadedbythispackage,therebyallowinganintegertobesubractedfromastd_logic_vector.LIBRARYieee;USEieee.std_logic_l164.Al丄;USEieee・std_logic_unsign
2、ed.ALL;ENTITYpldcntr8ISPORT(elk,load:INStd_logic;datain:INStdlogicvector(7DOWNTO0);q:OUTStd_logic_vector(7DOWNTO0);tc:OUTStd_logic);ENDpldcntrB;ARCHITECTUREusing_std_logicOFpldcntr8ISSIGNALcount:Std_logic_vector(7DOWNTO0);BEGINPROCESSBEGINWAITUNTILrising_edge(clk);IF
3、load二T'THENcount〈二datain;ELSEcount<=count-1;ENDIF;ENDPROCESS;tc<='1'WHENcount=〃00000000〃ELSE'O';q<=count;ENDusingstdlogic;条件赋值:使用whenelse语句——ConditionalSignalAssignmentLibraryIEEE;useIEEE.std_logic_l164.al1ENTITYcondsigISPORT(inputO,inputl,sei:INBIT;output:OUTBIT);EN
4、Dcondsig;ARCHITECTUREmaxpldOFcondsigISBEGINoutput<=inputOWHENsei='O'ELSEinputl;ENDmaxpld;加法器:generate语句的应用一一n-bitAdderusingtheGenerateStatementlibraryIEEE;useIEEE.Std_logic_1164.all;ENTITYaddnISGENERIC(n:POSITIVE:=3);—no.ofbitslessonePORT(addend,augend:INBIT_VECTOR(O
5、TOn);carryin:INBIT;carryout,overflow:OUTBIT;sum:OUTBTT_VECTOR(OTOn));ENDaddn;ARCHITECTUREgeneratedOFaddnISSIGNALcarries:BIT_VECTOR(0TOn);BEGINaddgen:FORiINaddend,RANGEGENERATElsadder:IFi=0GENERATEsum(i)<二addend(i)XORaugend(i)XORcarry_in;carries(i)<二(addend(i)ANDaugen
6、d(i))OR(addend(i)ANDcarry_in)OR(carryinANDaugend(i));ENDGENERATE;otheradder:IFi/=0GENERATEsum(i)<=addend(i)XORaugend(i)XORcarries(i~l);carries(i)〈二(addend(i)ANDaugend(i))OR(addend(i)ANDcarries(i-l))OR(carries(i~l)ANDaugend(i));ENDGENERATE;ENDGENERATE;carry_out<=carri
7、es(n);overflow<=carries(n~l)XORcarries(n);ENDgenerated;条件赋值:使用列举类型一一SelectedSignalAssignmentwithEnumerationTypeLibraryIEEE;useIEEE.std_logic_l164.all;PACKAGEmeals_pkgTSTYPEMEALIS(BREAKFAST,LUNCH,DINNER,MIDNIGI1T_SNACK);ENDmealspkg;USEwork,mealspkg.all;ENTITYselsigenI
8、SPORT(previous_meal:INMEAL;nextmeal:OUTMEAL);ENDsclsigcn;ARCHITECTUREmaxpldOFselsigenISBEGINWITHprevious_mealSELECTMTDNTGHT_SNACK,n
此文档下载收益归作者所有