§32VHDL的数据对象 数据对象:可以被赋值的客体 包括:常量( costant)、变量( variable)、信号( signal和文件(fle) 物理意义:常量——代表硬件电路中的电源和地,只能赋值一次; 变量——用于局部数据的暂时存储,是一种載体,可连续赋值; 信号——代表物理设计中某一条硬件连接线,可连续赋值; 文件——可作为参数向子程序传递,并通过子程序对文件进行读写操作。 321常量 常量——指在VHDL设计描述中不发生变化的值,常根据说明赋值。 常量说明 constant常量名常量名小数据类型[二=表达式; s] constant VCC: real: =3.3 constant nd1 gnd2 real: =0.0; constant delay time:=10ns, constant width: integer: =8 采用常量可改善VHDL程序的可读性,并使程序的修改更为方便
§3.2VHDL的数据对象 数据对象:可以被赋值的客体 包括:常量(costant)、变量(variable)、信号(signal)和文件(file) 物理意义:常量——代表硬件电路中的电源和地,只能赋值一次; 变量——用于局部数据的暂时存储,是一种载体,可连续赋值; 信号——代表物理设计中某一条硬件连接线,可连续赋值; 文件——可作为参数向子程序传递,并通过子程序对文件进行读写操作。 3.2.1 常量 常量——指在VHDL设计描述中不发生变化的值,常根据说明赋值。 常量说明: constant 常量名[, 常量名…]:数据类型[:=表达式]; 例: constant VCC: real:=3.3; constant GND1, GND2: real:=0.0; constant delay : time:=10ns; constant width: integer:=8; 采用常量可改善VHDL程序的可读性,并使程序的修改更为方便
常量必须在程序包、实体说明、结构体和进程的说明区域说明。 entity实体名is architecture结构体名of实体名is 类属说明 结构体说明语句 [端口说明引 egin [实体说明部分 功能描述语句; [实体语句部分〗 end[ architecture结构体名; end [entity实体名; 实体 结构体 [进程标号]poce敏感信号表] [进程语句说明部分;] begin 进程语句部分; end proces进程标号]; 进程
常量必须在程序包、实体说明、结构体和进程的说明区域说明。 entity 实体名is [类属说明;] [端口说明;] [实体说明部分;] [实体语句部分;] end [entity]实体名; 实体 architecture 结构体名 of 实体名 is [结构体说明语句;] begin 功能描述语句; end [architecture] 结构体名; 结构体 [进程标号:]process[敏感信号表][is] [进程语句说明部分;] begin 进程语句部分; end process [进程标号]; 进程
322变量和信号 1、变量 变量的作用:对暂时数据进行局部存储。 是一个局部量,在进程语句、过程语句和函数语句说明区说明。 变量说明格式 variable变量名,变量名…小:数据类型[约束条件][:=表达式 b]: variable count integer range 0 to 255: =0; variable tmp: std_logic=0, variable a, b: integer: =256, variable, y, z integer =16, variable clk_en: std_logic 变量赋值语句:目标变量:〓表达式; 2、信号 信号的作用:起着连线的作用,将实体与实体、元件与元件连接起来构成系统。 是一个全局量,在程序包、实体说明和结构体中都可以说明。 信号说明格式: signal信号名[信号名,1:数据类型[约束条件]=表达式
3.2.2 变量和信号 1、变量 变量的作用:对暂时数据进行局部存储。 是一个局部量,在进程语句、过程语句和函数语句说明区说明。 变量说明格式: variable 变量名[, 变量名…]:数据类型[约束条件][:=表达式]; 例: variable count: integer range 0 to 255 :=0; variable tmp: std_logic:=‘0’; variable a, b: integer :=256; variable x,y,z: integer:=16; variable clk_en: std_logic; 2、信号 信号的作用:起着连线的作用,将实体与实体、元件与元件连接起来构成系统。 是一个全局量,在程序包、实体说明和结构体中都可以说明。 信号说明格式: signal 信号名[, 信号名…]:数据类型[约束条件][:=表达式]; 变量赋值语句: 目标变量:=表达式;
B]: signal countl, count2: integer range 0 to 255: =0; signal clk: std_logic:=0, signal a, b integer: =165 signal data_bus: std_logic_vector(7 downto O); 信号赋值语句 目标信号<=表达式; 例:设计一个与非门电路 architecture one of nand 2is architecture one ofnand 2is signal ab: std_logic_vector(1 downto O); begin bes orocess(a 1S ab<=a& b: variable comb: std logic_vector(1 downto O); process(ab)is comb: =a b b egn begin case ab is case comb 1S when“00″=>c<= when“00”=>c<=‘1 when 111 when“01”=>c<=‘1 when“10 when >c<= when“11"=>c<="0 when11″=>c<=“0 when others =>null when others=>null; end case: end case en p rocess end process end one end one
例:signal count1, count2: integer range 0 to 255 :=0; signal clk: std_logic :=‘0’; signal a, b: integer :=16; signal data_bus: std_logic_vector(7 downto 0); 信号赋值语句: 目标信号 <= 表达式; 例:设计一个与非门电路 architecture one of nand_2 is signal ab: std_logic_vector (1 downto 0); begin ab<=a & b; process(ab) is begin case ab is when “00” => c<=‘1’ ; when “01” => c<=‘1’ ; when “10” => c<=‘1’ ; when “11” => c<=‘0’ ; when others =>null; end case; end process; end one; architecture one of nand_2 is begin process(a,b) is variable comb: std_logic_vector (1 downto 0); comb:=a & b; begin case comb is when “00” => c<=‘1’ ; when “01” => c<=‘1’ ; when “10” => c<=‘1’ ; when “11” => c<=‘0’ ; when others =>null; end case; end process; end one;
变量和信号的区别: (1)变量赋值是没有延迟的,而信号赋值是有延迟的; (2)变量只在定义它的进程、过程和函数中可见;而信号可是过个进程的全局信号。 (B)变量在硬件中没有一定的对应关系,而信号是硬件中连线的抽象描述。 例:设计三输入与非门电路 三输入与非门的真值表 NAND3 输入 输出 0 nst 0 三输入与非门电路 A00001111 B00110011 0 0 1 Y=ABC
变量和信号的区别: (1)变量赋值是没有延迟的,而信号赋值是有延迟的; (2)变量只在定义它的进程、过程和函数中可见;而信号可是过个进程的全局信号。 (3)变量在硬件中没有一定的对应关系,而信号是硬件中连线的抽象描述。 例:设计三输入与非门电路 NAND3 inst 三输入与非门的真值表 输 入 输 出 A B C Y 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 Y = ABC 1 1 1 0 三输入与非门电路