资源描述:
《fpga常用程序例子》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.或门的描述LIBRARYIEEE;USEIEEE.STDLOGIC1164.ALLENTITYorlISPORT(a,b:INSTD.LOGIC;y:OUTSTDLOGIC);ENDorl;ARCHITECTUREexample1OForlISBEGINy<=aORb;ENDexample1;2.半加器的描述LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYh_adderISPORT(a,b:INSTD_LOGIC;so,co:OUTSTD_LOGIC);END
2、h_adder;ARCHITECTUREexample2OFh.adderISBEGINso<=aXORb;co<=aANDb;ENDexample2;3.2选1数据选择器的描述LIBRARYIEEE;USEIEEE.STDLOGIC1164.ALLENTITYmux21ISPORT(a,b:INSTDLOGIC;s:INSTDLOGIC;y:OUTSTDLOGIC);ENDmux21;ARCHITECTUREexample3OFmux21ISBEGINy<=aWHENs=,0,ELSEb;ENDARCH
3、ITECTUREexample3;4.锁存器的描述LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYlatch1ISPORT(d:INSTD.LOGIC;ena:INSTD.LOGIC;q:OUTSTD_LOGIC);ENDlatch1;ARCHITECTUREexample4OFlatch1ISSIGNALsig_save:STD_LOGIC:=tO,;/*赋初始值(WBEGINPROCESS(d,ena)BEGINIFena二TTHENSig_save<=D;E
4、NDIF;Q<=sig_save;ENDPROCESS;ENDexample4;LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYcoderISPORT(a:INSTD_LOGIC_VECTOR(0TO7);y:OUTSTD_LOGIC_VECTOR(2DOWNTO0));ENDcoder;ARCHITECTUREexample2OFcoderISBEGINPROCESS(a)BEGINIFa(7)=,0,ELSIF(a(6)=,0,)ELSIF(a(5)='0,)
5、ELSIF(a(4)=,0,)ELSIF(a(3)=,0,)ELSIF(a(2)=,0,)ELSIF(a(l)=,0,)THENy<二”111”THENyv=T10“THENy<=,,10r,THENyv二TOO"THENy<="011nTHENyv二”010“THENyv=”001“ELSEyv=“000“;ENDIF;ENDPROCESS;ENDexample2;LIBRARYIEEE;USEIEEE.STDLOGIC1164.ALL;ENTITYmux41ISPORT(sl,s2:INSTD_LOG
6、IC;a,b,c,d:INSTD_LOGIC;z:OUTSTD.LOGIC);ENDmux41;ARCHITECTUREexample3OFmux41ISSIGNALs:STD_LOGIC_VECTOR(1DOWNTO0);BEGINs<=sl&s2;PROCESS(s1,s2,a,b,c,d)BEGINCASEsISWHEN”00“=>z<=a;WHEN”01“=>z<=b;WHENTO"=>z<=c;WHEN“11“=>z<=d;WHENOTHERS=>zv二X;ENDCASE;ENDPROCESS;
7、END;例1异步清零十进制加法计数器的描述LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYcntlOyISPORT(clr:INSTD_LOGIC;clk:INSTD_LOG1C;cnt:BUFFERINTEGERRANGE9DOWNTO0);ENDcntlOy;ARCHITECTUREexample9OFcntlOyISBEGINPROCESS(clr,cIk)BEGINIFclr=,O,THENcnt<=0;ELSIFclk'EVENTANDelk二'1'TH
8、ENIF(cnt=9)THENcnt<=0;ELSEcnt<=cnt+l;ENDIF;ENDIF;ENDPROCESS;ENDexample9;例求最大值的函数:LIBRARYIEEE;USEIEEE.STDLOGIC1164.ALL;PACKAGEbpacISFUNCTIONmax(a,b:INSTD_LOGIC_VECTOR)RETURNSTDJLOG1C_VECTOR;■■声明函数首END;PACKAGEBODYbpac