最新EDA-常见实例源程序代码vhdl.doc

上传人:1595****071 文档编号:34714847 上传时间:2022-08-18 格式:DOC 页数:359 大小:453.50KB
返回 下载 相关 举报
最新EDA-常见实例源程序代码vhdl.doc_第1页
第1页 / 共359页
最新EDA-常见实例源程序代码vhdl.doc_第2页
第2页 / 共359页
点击查看更多>>
资源描述

《最新EDA-常见实例源程序代码vhdl.doc》由会员分享,可在线阅读,更多相关《最新EDA-常见实例源程序代码vhdl.doc(359页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateEDA-常见实例源程序代码vhdlEDA-常见实例源程序代码vhdl第4章 用VHDL程序实现常用逻辑电路4.1 组合逻辑电路设计4.1.1 基本逻辑门library ieee;use iee.std_logic_1164.all;entity jbm is port(a,b: in bit; f1,f2,f3,f4,f5,f: out bit);end jbm;ar

2、chitecture a of jbm isbegin f1=a and b; -构成与门f2=a or b; -构成或门f=not a; -构成非门f3=a nand b; -构成与非门f4=a nor b; -构成异或门f5=not(a xor b); -构成异或非门即同门end; 4.1.2 三态门library ieee;use ieee.std_logic_1164.all;entity tri_s is port(enable: in std_logic;datain: in std_logic_vector(7 downto 0);dataout: out std_logic_v

3、ector(7 downto0);end tri_s;architecture bhv of tri_s isbegin process(enable,datain) begin if enable=1 then dataout=datain; else dataout=ZZZZZZZZ; end if; end process;end bhv;4.1.3 3-8译码器library ieee;use ieee.std_logic_1164.all;entity decoder3_8 is port(a,b,c,g1,g2a,g2b: in std_logic; y: out std_logi

4、c_vector(7 downto 0);end decoder3_8; architecture a of decoder3_8 issignal dz:std_logic_vector(2 downto 0);begin dz y y y y y y y yy=XXXXXXXX; end case; else y=11111111; end if; end process;4.1.4 优先编码器library ieee;use ieee.std_logic_1164.allentity coder is port(din: in std_logic_vector(0 to 7);outpu

5、t: out std_logic_vector(0 to 2);end coder;architecture behave of coder issignal sint: std_logic_vevtor(4 downto 0);begin process(din) begin if (din(7)=0) then output = 000 ; elsif (din(6)=0) then output = 100 ; elsif (din(5)=0) then output = 010 ; elsif (din(4)=0) then output = 110 ; elsif (din(3)=0

6、) then output = 001 ; elsif (din(2)=0) then output = 101 ; elsif (din(1)=0) then output = 011 ; else output led7s led7s led7s led7s led7s led7s led7s led7s led7s led7s led7s led7s led7s led7s led7s led7s null; end case;end process;end behave;4.1.6二-十进制BCD译码器library ieee;use ieee.std_logic_1164.all;u

7、se ieee.std_logic_signed.all;entity bcdymq is port(din : in integer range 15 downto 0; a,b : out integer range 9 downto 0);end; architecture fpq1 of bcdymq isbeginp1: process(din) begin if din10 then a =din; b =0; else a =din-10; bb+c0 then d=a-(b+c0); c1=0; else c1=1; d=(10000)-(b+c0-a); end if; en

8、d process ; end ; 4.2 时序逻辑电路设计4.2.1 触发器 RS触发器library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_signed.all; entity rsff is port(r,s,clk:in std_logic; q,qb:buffer std_logic); end rsff; architecture rsff_art of rsff is signal q_s,qb_s:std_logic; begin process(clk,r,s) begin if (clkevent and

9、 clk=1) then if (s=1 and r=0) then q_s=0 ; qb_s=1 ; elsif (s=0 and r=1) then q_s = 1 ; qb_s = 0 ; elsif (s=0 and r=0) then q_s = q_s; qb_s = qb_s; end if; end if; q_s = q_s; qb_s = qb_s; end process;end rsff_art; 同步复位D触发器library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_signed.all; entit

10、y syndff is port(d,clk,reset:in std_logic; q,qb:out std_logic); end syndff; architecture dff_art of syndff is begin process(clk) begin if (clkevent and clk=1) then if (reset=0) then q=0; qb=1; else q=d;qb=not q; end if; end if; end process; end dff_art; JK触发器 library ieee; use ieee.std_logic_1164.al

11、l; use ieee.std_logic_signed.all; entity asynjkff is port(j,k,clk,set.reset:in std_logic; q,qb:out std_logic); end asynjkff; architecture jkff_art of asynjkff is singal q_s,qb_s:std_logic; begin process(clk,set,reset) begin if (set=0 and reset=1 ) then q_s=1; qb_s=0; elsif (set=1 and reset=0 ) then

12、q_s=0; qb_s=1; elsif (clkevent and clk=1) then if (j=0 and k=1 ) then q_s=0; qb_s=1; elsif (j=1 and k=0 ) then q_s=1; qb_s=0; elsif (j=1 and k=1 ) then q_s=not q_s; qb_s=not qb_s; end if; end if; q= q_s; qb= qb_s; end process; end jkff_art;T触发器library ieee; use ieee.std_logic_1164.all; use ieee.std_

13、logic_signed.all; entity tff is port(t,clk: in std_logic; q: out std_logic); end; architecture tff_art of tff is signal q_temp: std_logic; begin p1:process(clk) begin if rising_edge(clk) then if t=1 then -当T=1时T触发器具有2分频的功能 q_temp=not q_temp; else q_temp=q_temp; end if; end if; q=q_temp; end process;

14、 q=q_temp; end tff_art;4.2.2计数器 library ieee; use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt4 ISport( clk: in std_logic; q: out std_logic_vector(3 downto 0);end cnt4;architecture behave of cnt4 issignal q1: std_logic_vector(3 downto 0);begin process(clk) begin if (clkevent an

15、d clk = 1) then q1=q1+1; end if;end process; q0); -计数器异步复位 elsif (clkevent and clk = 1) then -检测时钟上升沿 if en=1then -检测是否允许计数(同步使能) if updown=0then if cqi0); -大于9,计数值清零 end if; else if cqi0 then cqi:=cqi-1; -检测是否大于0 else cqi:=(others=1); -否则,计数值置1 end if; end if; end if; end if; cq=cqi; -将计数值向端口输出end

16、process; end behave;4.2.3 分频器library ieee;use std_logic_1164.all;use std_logic_unsigned.all;entity freq1 is port(clk: in std_logic; d: in std_logic_vector(7 downto 0);fout: out std_logic);end;architecture one of dvf issignal full: std_logic;beginp_reg:process(clk) variable cnt8: std_logic_vector(7 d

17、ownto 0); begin if clkevent and clk=1then -检测时钟上升沿 if cnt8=11111111 then cnt8:=d; -当CNT8计数计满时,输入数据D被同步预置给计数器CNT8 full=1; -同时使溢出标志信号FULL输出为高电平 else cnt8:=cnt8+1; -否则继续作加1计数 full=0; -且输出溢出标志信号FULL为低电平 end if; end if;end process p_reg;p_div:process(full)variable cnt2: std_logic;beginif fullevent and fu

18、ll=1 thencnt2:=not cnt2; -如果溢出标志信号FULL为高电平,T触发器输出取反if cnt2=1thenfout=1;elsefout reg (0) = c0 ; reg (7 downto 1) = reg (6 downto 0); cy reg (0) = reg (7); reg (7 downto 1) reg (7) = reg (0); reg (6 downto 0) reg (7) = C0 ; reg (6 downto 0) = reg (7 downto 1); cy reg (7 downto 0) reg= reg ; cy= cy ; -

19、保持 end case; end if; end process;qb(7 downto 0) = reg (7 downto 0); cn = cy; -移位后输出end behav;4.3 状态机逻辑电路设计4.3.1 一般状态机设计library ieee;use ieee.std_logic_1164.all;entity s_machine is port ( clk,reset : in std_logic; state_inputs : in std_logic_vector(0 to1); comb_outputs : out integer range 0 to 15 );e

20、nd s_machine;architecture behv of s_machine is type fsm_st is (s0, s1, s2, s3); -数据类型定义,状态符号化 signal current_state, next_state: fsm_st; -将现态和次态定义为新的数据类型begin reg: process(reset,clk) -主控时序进程begin if reset = 1 then current_state = s0; -检测异步复位信号 elsif clk=1 and clkevent then current_state comb_outputs=

21、 5; if state_inputs = 00 then next_state=s0; else next_state comb_outputs= 8; if state_inputs = 00 then next_state=s1; else next_state comb_outputs= 12; if state_inputs = 11 then next_state = s0; else next_state comb_outputs = 14; if state_inputs = 11 then next_state = s3; else next_state = s0; end

22、if; end case; end process;end behv;4.3.2状态机的应用library ieee;use ieee.std_logic_1164.all; entity asm_led is port(clk,clr : in std_logic; led1,led2,led3:out std_logic);end; architecture a of asm_led is type states is (s0,s1,s2,s3,s4,s5); -对状态机的状态声明 signal q: std_logic_vector( 0 to 2); signal state : st

23、ates;begin p1: process(clk,clr) begin if(clr=0)then state state state state state state state state=s0; end case; end if; end process p1; p2: process (clr,state) begin if(clr=0) then led1=0; led2=0; led3 led1=1;led2=0;led3 led1=0;led2=1;led3 led1=0;led2=1;led3 led1=0;led2=0;led3 led1=0;led2=0;led3 l

24、ed1=0;led2=0;led3 null; end case; end if; end process p2; end ; 第6章 EDA仿真技术应用实例6.1带使能和片选端的16:4线优先编码器设计 子模块设计源代码:library ieee;use ieee.std_logic_1164.all;entity pencoder isport(d:in std_logic_vector(7 downto 0);ei:in std_logic; -ei:enable inputgs,eo:out bit; -gs:chip select output;eo:enable outputq2,q1,q0:out std_logic); end pencoder;architecture encoder of pencoder isbeginprocess(d) beginif(d(0)=0 and ei=0)then q2=1;q1=1;q0=1; gs=0;eo=1;elsif(d(1)=0 and ei=0)then q2=1;q1=1;q0=0; gs=0;eo=1;elsif(d(2)=0 and ei=0)then q2=1;q1=0;q0=1;gs=0;eo=1;elsif(d(3

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 成人自考

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁