VHDL学习之模块调用

时间:2024-01-01 18:00:09

http://wenku.baidu.com/link?url=SsRPUVQAOKDR8yWfDhQlceCwfZQkI-KQMLFKTDGAh3KAPr2NwEgvj0d_EZjdnsB99Upp6hLzqWdxqHGGNZQcRJQCQpVBF8H8qkACAJY7A4_

这篇文章里说Function和Package中不能有时序电路,只能是组合逻辑电路。

任务:把常用的逻辑编译成库(不知道这个要干啥)

不理解库是干嘛用的

把当前理解做下笔记

1 这个是顶层模块

library ieee;
use ieee.std_logic_1164.all;
library work;
use work.nd2_pkg.all;
entity lib_test is
port(a,b:in std_logic;
     c,d:out std_logic);
end lib_test;

architecture behv of lib_test is
begin
    u1:entity work.h_adder port map(a,b,d);//component模块
    c <= max(a,b);//package中包含的function
end behv;

2 h_adder模块

一个单独的模块,顶层通过u1:entity work.h_adder port map(a,b,d);这句话调用,编译是h_adder.vhd这个文件要在工程目录下并且编译前要add source到ISE里;

library ieee;
use ieee.std_logic_1164.all;
entity h_adder is
port(a,b:in std_logic;
     c:out std_logic);
end entity h_adder;

architecture f1 of h_adder is
begin
     c <= a xor b;
end architecture f1;

3 package文件.好像package只能包含function之类的组合逻辑,并且

顶层加入

library work;
use work.nd2_pkg.all;

后能自动找到该文件,不用加add source在工程里。

library ieee;
use ieee.std_logic_1164.all;
package nd2_pkg is

function max(a,b:in std_logic) return std_logic;

end nd2_pkg;

package body nd2_pkg is

function max(a,b:in std_logic) return std_logic is
begin
    if a > b then
        return a;
    else
        return b;
    end if;
end function max;

end nd2_pkg;