1 / 23

第 3 章 VHDL 基础

第 3 章 VHDL 基础. 3.6 数据对象 P67. 在 VHDL 中,数据对象有 3 类:常量( constant )、变量( variable )、 信号( signal ) 3.6.1 常量 常量的定义和设置主要是为了使程序更容易阅读和修改。 定义的一般表述方法: Constant 常量名:数据类型: = 表达式 例: constant X :std_logic_vector:=“010110”

gil
Télécharger la présentation

第 3 章 VHDL 基础

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第3章 VHDL基础 3.6 数据对象 P67 在VHDL中,数据对象有3类:常量( constant )、变量(variable)、 信号(signal) 3.6.1 常量 常量的定义和设置主要是为了使程序更容易阅读和修改。 定义的一般表述方法: Constant 常量名:数据类型:=表达式 例:constant X:std_logic_vector:=“010110” 定义常数X的数据类型是std_logic_vector,它等于“010110” constant Y:integer:=15 定义常数Y的数据类型是integer,它等于15

  2. 常数使用范围说明:P131 常数的使用范围取决于它被定义的位置。 库 包集合 实体 构造体 进程 1、当常数CS是在包集合里被定义的,那它可以在调用此包集 合的所有程序中使用。 2、当常数CS是在某一程序的实体里被定义的,那它只可以在 该程序的实体、构造体、进程中使用。 3、当常数CS是在某一程序的构造体里被定义的,那它只可以 在该程序的该构造体、该进程中使用。 4、当常数CS是在构造体里某一进程中被定义的,那它只可以 在该进程中使用。

  3. 3.6.2 变量 P68 • 变量是局部量,只能在进程和子程序中被定义和使用,主要是作为临时的数据存储单元。 1、定义方式: • variable 变量名称:数据类型 :=初始值; 例: • Variable a:integer range 0 to 15 ; 定义变量a为整数类型,取值范围在0~15。 • Variable b:std_logic :=‘1’; 定义变量b为std_logic(标准位)类型,初始值为‘1’,后面如果程序 有对它赋值,b的数值将=最后的赋值。 2、赋值方式 变量名:=表达式 • a:=b; • b:=3.0; • c:=d+e;

  4. 3.6.3 信号 信号是全局量,能在包集合、实体、结构体中被定义和使用,主要是作为类似于连接线的作用。在进程和子程序中是不能被定义。 1、定义方式: signal 变量名称:数据类型 :=初始值; 例: signal c:integer range 0 to 15 ; 定义信号量a为整数类型,取值范围在0~15。 signal d:std_logic :=‘1’; 定义信号量b为std_logic(标准位)类型,初始值为‘1’ 。 2、赋值方式 信号量名 <= 表达式 A <= b; B <= 3.0; C <= d+e;

  5. 3.6.4 信号和变量的区别

  6. 例5-3 例5-4 Architecture bhv of dff3 is Signal a,b:std_logic; Begin Process(clk) Begin If (clk’event and clk=‘1’) then a <= D1; b <= a; Q1 <= b; End if; End process; End bhv; Architecture bhv of dff4 is Begin Process(clk) Variable a,b:std_logic; Begin If (clk’event and clk=‘1’) then a := D1; b := a; Q1 := b; End if; End process; End bhv;

  7. 例5-3 (信号) 例5-4 (变量)

  8. 六盏彩灯控制CD1 • 要求 1、六盏灯编号分别为Y1、Y2、Y3、Y4、Y5、Y6; 2、有一“控制方式选择键”,当电路的电源接通后,该选择键为‘0’时,彩灯点亮顺序为Y1、Y3、Y5。 3、当该选择键为‘1’时,彩灯点亮顺序为Y2、Y4、Y6。 4、每盏灯依次隔1秒被点亮。 画出外围电路、写出流程

  9. if (clk'event and clk='1')then if (xz='0') then a1<='1'; c3<=a1; e5<=c3; elsif (xz='1') then b2<='1'; d4<=b2; f6<=d4; end if; end if; y1<=a1; y2<=b2; y3<=c3; y4<=d4; y5<=e5; y6<=f6; end process ; end rtl; • 程序 • library ieee; • use ieee.std_logic_1164.all; • use ieee.std_logic_arith.all; • use ieee.std_logic_signed.all; • entity cd1 is • port(clk,xz:in std_logic; • y1,y2,y3,y4,y5,y6:out std_logic); • end cd1; • architecture rtl of cd1 is • signal a1,b2,c3,d4,e5,f6:std_logic; • Begin • process(clk,xz) • begin

  10. cd1

  11. 六盏彩灯控制CD2 • 要求 1、六盏灯编号分别为Y1、Y2、Y3、Y4、Y5、Y6; 2、有一“控制方式选择键”,当电路的电源接通后,该选择键为‘0’时,彩灯点亮顺序为Y1、Y3、Y5。 3、当该选择键为‘1’时,彩灯点亮顺序为Y2、Y4、Y6。 4、每盏灯依次隔1秒被点亮,按下复位键灯都灭。 画出外围电路、写出流程

  12. 程序 • entity cd2 is • port(clk,xz:in std_logic; • y1,y2,y3,y4,y5,y6:out std_logic); • end cd2; • architecture rtl of cd2 is • signal a1,b2,c3,d4,e5,f6:std_logic; • Begin • process(clk,xz,rs) • Begin • If (rs='1') then • a1<='0'; b2<='0'; • c3<='0'; d4<='0'; • e5<='0'; f6<='0'; elsif (clk'event and clk='1')then if (xz='0') then a1<='1'; c3<=a1; e5<=c3; elsif (xz='1') then b2<='1'; d4<=b2; f6<=d4; end if; end if; y1<=a1; y2<=b2; y3<=c3; y4<=d4; y5<=e5; y6<=f6; end process ; end rtl;

  13. cd2

  14. 3人抢答器1 • 要求 • 1、第1个按下抢答按钮的人,抢答器将点亮他的灯并保持,其他2人的抢答信号无效。 • 2、主持人按下复位键后,灯灭,才可以接受下一次的抢答。 画出外围电路、写出流程

  15. entity qdq1 is port(q1,q2,q3,rs:in std_logic; y1,y2,y3:out std_logic); end qdq1; architecture rtl of qdq1 is signal qd,xh:std_logic; begin process(q1,q2,q3,qd,rs,xh) begin qd<=q1 or q2 or q3; if (rs='1') then y1<='0'; y2<='0'; y3<='0'; xh<='0'; elsif (qd'event and qd='1')then if (q1='1' and xh='0') then y1<='1'; y2<='0'; y3<='0'; xh<='1'; elsif (q2='1' and xh='0') then y1<='0'; y2<='1'; y3<='0'; xh<='1'; elsif (q3='1' and xh='0') then y1<='0'; y2<='0'; y3<='1'; xh<='1'; end if; end if; end process ; end rtl;

  16. qdq1

  17. 3人抢答器2 • 要求 • 1、第1个按下抢答按钮的人,抢答器将 点亮他的灯并保持,其他2人的抢答信号无效。 • 2、如果同时有2人或3人按下抢答按钮,抢答信号无效。 • 3、主持人按下复位键后,灯灭,才可以接受下一次的抢答。 • 4、显示第1个抢答成功的号码。

  18. 防盗产品3 参考答案 要求: • 1、当有人靠近红外线探测器工作范围时,要求有闪烁的红 • 光和报警声。 • 2、“功能选择键”为‘0’低电平时选择A的功能要求,当“功能 • 选择键”为‘1’高电平时选择B的功能要求, • A、当人离开红外线探测器工作范围时,要求立即停止闪烁的红光和报警声。 • B、当人离开红外线探测器工作范围时,闪烁的红光和报警声仍然存在,只有按下复位键,才能停止闪烁的红光和报警声。 • 作业要完成内容: • 1、外围电路 • 2、程序 • 3、仿真后的正确波形图

  19. 防盗产品3 architecture rtl of fang_dao3 is begin process(fdxh,rs,xz) begin if( rs='1‘)then bjsy<='0'; bjdg<='0'; elsif(xz='0' and fdxh='1') then bjsy<='1'; bjdg<='1'; elsif (fdxh'event and fdxh='1') then if(xz='1')then bjsy<='1'; bjdg<='1'; end if; end if; end process ; end rtl;

  20. entity fang_dao3 is port(fdxh,rs,xz,pd:in std_logic; bjsy,bjdg:out std_logic); end fang_dao3; architecture rtl of fang_dao3 is begin process(fdxh,rs,xz,pd) begin if( rs='1' or (pd='0' and xz='0' and fdxh='0'))then bjsy<='0'; bjdg<='0'; elsif(xz='0' and fdxh='1') then bjsy<='1'; bjdg<='1'; elsif (fdxh'event and fdxh='1') then if(xz='1')then bjsy<='1'; bjdg<='1'; end if; end if; end process ; end rtl;

More Related