欢迎来到天天文库
浏览记录
ID:12552675
大小:42.50 KB
页数:8页
时间:2018-07-17
《用vhdl编写的各种功能的计数器代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、LibraryIEEE;useIEEE.std_logic_1164.all;useIEEE.std_logic_arith.all;ENTITYcountersISPORT(d:ININTEGERRANGE0TO255;clk:INBIT;clear:INBIT;ld:INBIT;enable:INBIT;up_down:INBIT;qa:OUTINTEGERRANGE0TO255;qb:OUTINTEGERRANGE0TO255;qc:OUTINTEGERRANGE0TO255;qd:OUTINTE
2、GERRANGE0TO255;qe:OUTINTEGERRANGE0TO255;qf:OUTINTEGERRANGE0TO255;qg:OUTINTEGERRANGE0TO255;qh:OUTINTEGERRANGE0TO255;qi:OUTINTEGERRANGE0TO255;qj:OUTINTEGERRANGE0TO255;qk:OUTINTEGERRANGE0TO255;ql:OUTINTEGERRANGE0TO255;qm:OUTINTEGERRANGE0TO255;qn:OUTINTEGERR
3、ANGE0TO255);ENDcounters;ARCHITECTUREaOFcountersISBEGIN--AnenablecounterPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO255;BEGINIF(clk'EVENTANDclk='1')THENIFenable='1'THENcnt:=cnt+1;ENDIF;ENDIF;qa<=cnt;ENDPROCESS;--AsynchronousloadcounterPROCESS(clk)VARIABLEcnt:I
4、NTEGERRANGE0TO255;BEGINIF(clk'EVENTANDclk='1')THENIFld='0'THENcnt:=d;ELSEcnt:=cnt+1;ENDIF;ENDIF;qb<=cnt;ENDPROCESS;--AsynchronousclearcounterPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO255;BEGINIF(clk'EVENTANDclk='1')THENIFclear='0'THENcnt:=0;ELSEcnt:=cnt+1;E
5、NDIF;ENDIF;qc<=cnt;ENDPROCESS;--Anup/downcounterPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO255;VARIABLEdirection:INTEGER;BEGINIF(up_down='1')THENdirection:=1;ELSEdirection:=-1;ENDIF;IF(clk'EVENTANDclk='1')THENcnt:=cnt+direction;ENDIF;qd<=cnt;ENDPROCESS;--Asy
6、nchronousloadenablecounterPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO255;BEGINIF(clk'EVENTANDclk='1')THENIFld='0'THENcnt:=d;ELSEIFenable='1'THENcnt:=cnt+1;ENDIF;ENDIF;ENDIF;qe<=cnt;ENDPROCESS;--Anenableup/downcounterPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO255
7、;VARIABLEdirection:INTEGER;BEGINIF(up_down='1')THENdirection:=1;ELSEdirection:=-1;ENDIF;IF(clk'EVENTANDclk='1')THENIFenable='1'THENcnt:=cnt+direction;ENDIF;ENDIF;qf<=cnt;ENDPROCESS;--AsynchronousclearenablecounterPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO25
8、5;BEGINIF(clk'EVENTANDclk='1')THENIFclear='0'THENcnt:=0;ELSEIFenable='1'THENcnt:=cnt+1;ENDIF;ENDIF;ENDIF;qg<=cnt;ENDPROCESS;--AsynchronousloadclearcounterPROCESS(clk)VARIABLEcnt:INTEGERRANGE0TO255;BEGINIF(clk'EVENTANDclk='
此文档下载收益归作者所有