資源描述:
《EDA中用VHDL語(yǔ)言編程的實(shí)驗(yàn).doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、EDA課程中VHDL的分頻程序(1)將32KHz分成1KHz占空比百分之五十LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYfenpinISPORT(CLK:INSTD_LOGIC;q:OUTSTD_LOGIC);ENDfenpin;ARCHITECTUREarcOFfenpinISsignalwire:std_logic;BEGINPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO31;BEGINIFclk'EVENTANDclk='1
2、'THENIFcnt<16THENcnt:=cnt+1;--ifcnt=7thenwire<='0';endif;可以通過(guò)這綠色字體修改占空比。ELSEcnt:=0;--q<='1';wire<=notwire;ENDIF;ENDIF;ENDPROCESS;q<=wire;ENDarc;(2)9進(jìn)制計(jì)數(shù)器程序如下LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;ENTITYCNT9ISPORT(CLK1,RST,EN:
3、INSTD_LOGIC;CQ:OUTSTD_LOGIC_VECTOR(3DOWNTO0));ENDCNT9;ARCHITECTUREbehaveOFCNT9ISBEGINPROCESS(CLK1,RST,EN)VARIABLECQI:STD_LOGIC_VECTOR(3DOWNTO0);BEGINIFRST='1'THENCQI:=(OTHERS=>'0');ELSIFCLK1'EVENTANDCLK1='1'THENIFEN='1'THENIFCQI<8THENCQI:=CQI+1;ELSECQI:=(O
4、THERS=>'0');ENDIF;ENDIF;ENDIF;CQ<=CQI;ENDPROCESS;ENDbehave;(3)譯碼器的程序編寫(xiě)。USEIEEE.STD_LOGIC_1164.ALL;ENTITYDECL7SISPORT(D:INSTD_LOGIC_VECTOR(3DOWNTO0);A:INSTD_LOGIC_VECTOR(2DOWNTO0);B:OUTSTD_LOGIC_VECTOR(2DOWNTO0);LED7S:OUTSTD_LOGIC_VECTOR(6DOWNTO0));ENDDECL7
5、S;ARCHITECTUREoneOFDECL7SISBEGINB<=A;PROCESS(D)BEGINCASEDISWHEN"0000"=>LED7S<="0111111";WHEN"0001"=>LED7S<="0000110";WHEN"0010"=>LED7S<="1011011";WHEN"0011"=>LED7S<="1001111";WHEN"0100"=>LED7S<="1100110";WHEN"0101"=>LED7S<="1101101";WHEN"0110"=>LED7S<="111
6、1101";WHEN"0111"=>LED7S<="0000111";WHEN"1000"=>LED7S<="1111111";WHEN"1001"=>LED7S<="1101111";WHENOTHERS=>NULL;ENDCASE;ENDPROCESS;END;將上述三個(gè)程序主合成一個(gè)通過(guò)將32KHz分成1KHz,在譯碼器上顯示數(shù)字0到9.的主合程序,,,需進(jìn)行元件例化。。例化程序如下:LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;ENTITYKONISPORT(ain,
7、bin,cin:INSTD_LOGIC;AN:INSTD_LOGIC_VECTOR(2DOWNTO0);BN:OUTSTD_LOGIC_VECTOR(2DOWNTO0);YOUT:OUTSTD_LOGIC_VECTOR(6DOWNTO0));ENDKON;ARCHITECTUREoneOFKONISCOMPONENTfenpinPORT(CLK:INSTD_LOGIC;Q:OUTSTD_LOGIC);ENDCOMPONENT;COMPONENTCNT9PORT(CLK1,RST,EN:INSTD_LOGIC
8、;CQ:OUTSTD_LOGIC_VECTOR(3DOWNTO0));ENDCOMPONENT;COMPONENTDECL7SPORT(D:INSTD_LOGIC_VECTOR(3DOWNTO0);A:INSTD_LOGIC_VECTOR(2DOWNTO0);B:OUTSTD_LOGIC_VECTOR(2DOWNTO0);LED7S:OUTSTD_LOGIC_VECTOR(6DOWNTO0));ENDCOMPON