资源预览内容
第1页 / 共87页
第2页 / 共87页
第3页 / 共87页
第4页 / 共87页
第5页 / 共87页
第6页 / 共87页
第7页 / 共87页
第8页 / 共87页
第9页 / 共87页
第10页 / 共87页
亲,该文档总共87页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
VHDL语言目录 概述第一章 VHDL的程序结构和软件操作 第二章 数据类型与数据对象的定义第三章 并行赋值语句第四章 顺序赋值语句第五章 组合逻辑电路的设计第六章 时序逻辑电路的设计第七章 子程序、库和程序包第八章 CPLD和FPGA的结构与工作原理 第九章 数字钟电路的设计 第一章 VHDL的程序结构和软件操作 1-1 VHDL程序的基本结构1-1 VHDL程序的基本结构include “stdio.h”; include “math.h”;int main(void) int a,b,c;a=8;b=9;c=a+b;return c; Library std; Use std.standard.all; Entity and2 is Port( a,b : in bit; c : out bit); End and2; Architecture a1 of and2 is Beginc ) of BIT; type BIT is (0, 1); type BOOLEAN is (FALSE, TRUE) ;(4)标准逻辑型(Std_Logic);Type STD_LOGIC is (U, -Uninialized;未初始化X, -Forcing unknown;浮接不定0, - Forcing 0;低电位1, - Forcing 1;高电位 Z, - High Impedance;高阻抗W, - Weak Unknown;弱浮接L, - Weak 0;弱低电位 H, - Weak 1;弱高电位-, - Dont care;不必理会 );(5)标准逻辑数组类型(Std_Logic_vector);在ieee库的std_logic_1164程序包中定义。 TYPE std_logic_vector IS ARRAY ( NATURAL RANGE ) of STD_LOGIC; type SIGNED is array (NATURAL range = 大于或等于注:其中0); 结果信号A的每一位的值都为0。 B0); 信号对象的位数很多时,采用others来赋值很方便。End Block; (5) Block(块)语句 library ieee; use ieee.std_logic_1164.all; entity exam1 is port (a,b,c : in std_logic;d,e : out std_logic); end exam1; architecture m1 of exam1 is begin Block_1: Block Begind映射符号进行输入信号和元件信号之间的 映射,那么位置可以不对应。即:元件标号:元件名 Port Map(元件信号A=信号A1, 元件信号B=信号B1,); 注意!元件标号是必需的。Component例化语句 Library ieee; Use ieee.std_logic_1164.all; Use ieee.std_logic_unsigned.all; Entity fulladder is Port(Ci : in std_logic;a,b : in std_logic;s : out std_logic;Co : out std_logic); End fulladder; Architecture m1 of fulladder is Signal tmp: std_logic_vector(1 downto 0); Begin tmpc(0),a=x(0),b=y(0),s=sum(0),co=c(1); U2: fulladder Port map(c(1),x(1),y(1),sum(1),c(2); U3: fulladder Port map(c(2),x(2),y(2),sum(2),c(3); U4: fulladder Port map(c(3),x(3),y(3),sum(3),c(4); Cout8)Port map(cin1,x1,y1,sum1,cout1); End a;-若元件声明时已经赋值,则Nadder: adder Port map(cin1,x1,y1,sum1,cout1);Generic map(8)(1)顺序语句每一条语句的执行都是顺序进行的。如同高级编 程语言中的命令执行方式,一次一条命令,按书写顺序由上而 下执行。(2)顺序语句只能出现在进程和子程序内部。(3)由于顺序语句的次序很重要,因此,顺序语句要与并行语 句分割开,这可以通过Process语句来实现。Process语句出现 在结构体中,它将其内部的语句进行封装。第四章 顺序赋值语句 顺序语句有三个特点:a.所有语句的执行是顺序进行的;b.每条语句的执行和其所在的位置有关;c.顺序语句的输出不仅依赖于输入,而且还受位置的影响。第四章 顺序语句 n(1)Process语句 n(2)If-Else语句 n(3)Case-When语句 n(4)Null语句 n(5)For-Loop语句 n(6)Wait until语句 n(7)变量赋值语句 n(8) Procedure(过程)调用语句 (1)Process语句Process 内的顺序语句可以是: Process-label:Process(Sensitivity list)Variable declarations -变量声明 Begin wait until statement variable assignment statements if statements case statements Procedure调用语句 End Process;(2)If-Else语句If expression1 Thenstatement1;statement; Elsif expression2 Thenstatement2;statement;Elsestatement3;statement; End if; 语法格式:If-Else语句示例例如: If Sel=“01” thenfstatement1;statement;When constant_value2 =statement2;statement;When others =statement3;statement; End case;语法格式:Case-When语句示例Case Sel IsWhen “00” =ffff -s=2 or s=3 or s=4PPnull;End case;(5)For-Loop语句For-Loop为循环语句,可以使其所包含的顺序语句 被循环执行,它类似于并行语句中For-generate生 成语句。 语法格式为: loop_label: For variable_name In range LoopStatement; Statement; End Loop;Library ieee; Use ieee.std_logic_1164.all; Entity lp is generic(n:integer:=8); Port(din : in std_logic_vector(1 to n);Count :out integer range 0 to n); End lp; Architecture m1 of lp is Begin process(din) variable tmp:integer range 0 to n; begin tmp:=0; for j in 1 to n loop if din(j)=1 then tmp:=tmp+1; end if; end loop; countd1,b=d2,y=tmp); do=tmp; end process; End a;二位与的过程
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号