最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

VHDL之wait 和function、Procedure的用法

来源:动视网 责编:小OO 时间:2025-10-02 02:23:27
文档

VHDL之wait 和function、Procedure的用法

1.--在VHDL中,waituntilclk='1'可替代clk'eventandclk='1'做上升沿,--waituntilclk='0'可以替代clk'eventandclk='1'做下降沿。具体用法如下:--74hc161功能芯片的VHDL程序:Libraryieee;useieee.std_logic_11.all;useieee.std_logic_unsigned.all;entityd_ffisPort(clk,cr,ld:instd_logic;    d:instd_
推荐度:
导读1.--在VHDL中,waituntilclk='1'可替代clk'eventandclk='1'做上升沿,--waituntilclk='0'可以替代clk'eventandclk='1'做下降沿。具体用法如下:--74hc161功能芯片的VHDL程序:Libraryieee;useieee.std_logic_11.all;useieee.std_logic_unsigned.all;entityd_ffisPort(clk,cr,ld:instd_logic;    d:instd_
1.--在VHDL中,wait until clk='1' 可替代clk'event and clk='1'做上升沿,

--wait until clk='0' 可以替代clk'event and clk='1'做下降沿。具体用法如下:

--74hc161功能芯片的VHDL程序:

Library ieee;

use ieee.std_logic_11.all;

use ieee.std_logic_unsigned.all;

entity d_ff is

Port(clk,cr,ld:in std_logic;

     d:in std_logic_vector(3 downto 0);

      q:out std_logic_vector(3 downto 0));

end;

architecture dd of d_ff is

signal s,ss:std_logic_vector(3 downto 0);

begin

  process 

   begin    

    wait until clk='1';    --这句意思是等待到clk等于1时完成下面语句

       if ld='0' then s<=d;

         else s<=s+1 ;

       end if;

    if cr='0' then

      s<="0000";

    end if;

  end process;

  q<=s;

end dd;

2--子程序也是很多编程语言中常用的程序模块,VHDL子程序用法如下:

  1)---------------子程序function的用法--------------------- 

Library ieee;

use ieee.std_logic_11.all;

use ieee.std_logic_unsigned.all;

entity full_adder is

Port(a,b,cin:in std_logic;

     sum,co:out std_logic);      

end;

architecture add of full_adder  is

 Function sam1(x,y:std_logic)return std_logic is   --子程序1,sam1为程序名

   begin                           --x,y为子程序变量,冒号后面是变量类型

   return (x xor y);          --子程序返回值

  end sam1;  --结束子程序1

  function sam2(x,y:std_logic)return std_logic is    --子程序2

   begin

   return (x and y);

  end sam2;   --结束子程序1

signal s1,co1,s2,co2,ss:std_logic;

begin

  process(a,b,cin) 

   begin    

     s1<=sam1(a,b);   --调用子程序1

     co1<=sam2(a,b); --调用子程序2

     s2<=sam1(s1,cin);

     co2<=sam2(s1,cin);   

   end process;  

   sum<=s2;

   co<=co1 or co2;  

end dd;

  2)---------------子程序Procedure的用法--------------------- 

Library ieee;

use ieee.std_logic_11.all;

use ieee.std_logic_unsigned.all;

entity d_ff is

Port(a,b,cin:in std_logic;

     sum,co:out std_logic);      

end;

architecture dd of d_ff is

---------------------------------------

 Procedure sam1(x,y:in std_logic;

                z: out std_logic) is   --这个子程序用法变量必须设置方向

   begin

   z:=(x xor y);                           --赋值必须采用变量Veriable格式:=

  end sam1;

----------------------------------------

 Procedure sam2(x1,y1:in std_logic;

                z1: out std_logic) is

   begin

   z1:=(x1 and y1);

  end sam2;

-----------------------------------------

begin

  process(a,b,cin) 

  variable s1,s2,co1,co2:std_logic;--运行过程中需要的话,必须使用局部变量,在Process后设置。

   begin 

   sam1(a,b,s1);

   sam2(a,b,co1);

   sam1(s1,cin,s2);

   sam2(s1,cin,co2);   

    sum<=s2;

   co<=co1 or co2;      

   end process;      

end dd;

文档

VHDL之wait 和function、Procedure的用法

1.--在VHDL中,waituntilclk='1'可替代clk'eventandclk='1'做上升沿,--waituntilclk='0'可以替代clk'eventandclk='1'做下降沿。具体用法如下:--74hc161功能芯片的VHDL程序:Libraryieee;useieee.std_logic_11.all;useieee.std_logic_unsigned.all;entityd_ffisPort(clk,cr,ld:instd_logic;    d:instd_
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top