您好,欢迎访问三七文档
VHDL语法格式1上篇基础元素目录:数据类型数据对象运算符语句基本程序结构电路描述方式数据类型预定义类型bitbit_victorintegerstd_logicstd_logic_victor自定义类型枚举类型type新数据类型is(元素1,元素2,...)例定义typestate_typeis(s1,s2,s3.s4);--定义一个新类型state_type引用signalstate:state_type;--定义一个信号state,类型为state_type数组类型type数组isarray(范围)of数据类型;例定义typebyteisarray(7downto0)ofbit;--定义一个8bit的数组typewordisarray(31downto0)ofbit;--定义一个32bit的数组数据对象端口声明端口:in|out数据类型;--端口在特性上等同于信号,但赋值在entity的port中赋值端口=表达式;信号声明signal信号:数据类型;赋值信号=表达式;变量声明varable变量:数据类型;赋值变量:=表达式;常数声明常数:数据类型:=数值;运算符算术运算+,-,*并置运算&关系运算=,/=,,=,,=逻辑运算and,or,not,nand,nor,xor,xnor语句并行语句⑴信号赋值语句简单信号赋值语句信号=表达式;选择信号赋值语句with选择表达式select信号=表达式1when选择值1,VHDL语法格式2表达式2when选择值2,......表达式nwhenothers;条件信号赋值语句信号=表达式1when条件关系式1else表达式2when条件关系式2else......表达式nwhen条件nelse表达式;⑵过程调用语句过程(实参);⑶函数调用语句信号=函数(实参);⑷元件例化语句元件声明component元件实体--将一个实体声明为元件port(端口声明);endcomponent;元件引用按位置引用标号:元件实体portmap(连接端口1,连接端口2,...);按名称引用标号:元件实体portmap(元件端口1=连接端口1,元件端口2=连接端口2,...);⑸生成语句格式1[标号:]for循环变量in取值范围generate声明语句,begin并行语句,endgenerate[标号];取值范围:表达式to表达式;--递增方式,如1to5表达式downto表达式;--递减方式,如5downto1格式2[标号:]if条件关系式generate声明语句;begin并行语句,endgenerate[标号],⑹块语句块标号:block[(保护条件)]接口声明;类属声明;begin并行语句;--被保护的变量前需加上保留字guardedendblock块标号;带保护的块语句举例:entitylatchisport(d,clk:inbit;q,qb:outbit);VHDL语法格式3endlatch;achetectirelatch_guardoflatchisbeginb1:block(clk=1)beginq=guardeddafter5ns;qb=guardednot(d)after7ns;endblockb1;endlatch_guard⑺进程语句[标号:]process(敏感信号)[声明语句;]--常量,变量,信号begin顺序语句;endprocess[标号:];顺序语句⑴赋值语句--在进程中信号=表达式;变量:=表达式;⑵流程控制语句if语句格式1:if条件关系式then顺序语句;endif;格式2:if条件关系式then顺序语句;else顺序语句;endif;格式3:if条件关系式1then顺序语句;elsif条件关系式2then顺序语句;......else顺序语句;endif;VHDL语法格式4case语句--case语句中,条件值有3种形式:值,值1|值2|...|值n,值TO值--最后一行的顺序语句若为null,则有意引入锁存器case条件表达式iswhen条件值=顺序语句;......whenothers=顺序语句;endcase;for_loop语句[标号]:for循环变量in值to值loop;顺序语句;endloop[标号];时钟边沿描述上升沿时钟eventand时钟=1|rising_edge(时钟)下降沿时钟eventand时钟=0|falling_edge(时钟)程序基本结构--主程序与元件程序在同一文件work1.vhd中,libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;--主程序entity实体名is--实体名必须与文件名相同port(端口声明;);endentitywork1;architecturestrucofwork1is[声明语句;]--常量,变量,信号,元件,函数等begin并行语句;endarchitecturestruc;电路描述方式行为描述方式以用状态机描述电路为典型数据流(寄存器)描述方式即用逻辑表达式描述电路结构描述方式以用元件复用的方式描述电路为典型VHDL语法格式5下篇复合元素和状态机目录元件----------1单文件元件2多文件元件函数----------3单文件函数4多文件函数过程----------5单文件过程6多文件过程moorl状态机--7二进程moorl状态机8三进程moorl状态机meaky状态机--9二进程mealy状态机10三进程mealy状态机状态机实例----11交通灯之一12交通灯之二附录----------13状态转移图14用户库的格式和用法单文件元件--主程序与元件程序在同一文件work1.vhd中,libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;--主程序entitywork1isport(r,s,t,u:instd_logic;v:outstd_logic);endentitywork1;architecturestrucofwork1iscomponentym--将实体ym声明为元件port(a,b:instd_logic;c:outstd_logic);endcomponentym;componenthm--将实体hm声明为元件port(a,b:instd_logic;c:outstd_logic);endcomponenthm;signaltemp1,temp2:std_logic;beginu1:ymportmap(r,s,temp1);--元件例化u2:ymportmap(t,u,temp2);u3:hmportmap(temp1,temp2,v);endarchitecturestruc;--ym元件实体定义程序libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityymisport(a,b:instd_logic;c:outstd_logic);endentityym;architectureym1ofymisbeginc=aandb;endarchitectureym1;--hm元件实体定义程序libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityhmisport(a,b:instd_logic;c:outstd_logic);endentityhm;VHDL语法格式6architecturehm1ofhmisbeginc=aorb;endarchitecturehm1;多文件元件--主程序文件和定义元件的程序文件都要添加到工程中--主程序文件zhu_map.vhd,不需要...声明用户库文件libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityzhu_mapisport(r,s,t,u:instd_logic;v:outstd_logic);endentityzhu_map;architectureniuofzhu_mapiscomponentymport(a,b:instd_logic;c:outstd_logic);endcomponentym;componenthmport(a,b:instd_logic;c:outstd_logic);endcomponenthm;signaltemp1,temp2:std_logic;beginu1:ymportmap(r,s,temp1);--元件例化u2:ymportmap(t,u,temp2);u3:hmportmap(temp1,temp2,v);endarchitectureniu;--定义元件实体的程序文件--ym元件实体定义程序libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityymisport(a,b:instd_logic;c:outstd_logic);endentityym;architectureym1ofymisbeginc=aandb;endarchitectureym1;--hm元件实体定义程序libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityhmisport(a,b:instd_logic;c:outstd_logic);endentityhm;architecturehm1ofhmisbeginc=aorb;endarchitecturehm1;单文件函数libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;entityfuncisport(din1,din2:instd_logic_vector(0to3);dout:outstd_logic_vector(0to3));endentity;VHDL语法格式7architectureaoffuncis--定义函数functionls_xj(d1,d2:instd_logic_vector(0to3))returnstd_logic_vectorisvariabletemp:std_logic_vector(0to3);begintemp:=d1+d2;returntemp;endfunction;--定义函数结束begindout=ls_xj(din1,din2);--调用函数endarchitecture;多文件函数--主程序文件和定义函数的程序文件都要添加到工程中--主程序文件zhu_func.vhd,必须声明用户库文件libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;usework.use_func.all;--use_func.vhd作为用户库entityzhu_funcisport(din1,din2:instd_logic_vector(0to3);dout:outstd_logic_vector(0to3));end;architectureniuofzhu_funcisbegindout=ls_xj(din1,din2);--调用函数end;--定义函数的文件fu_func.vhdlibraryieee;useieee.std_logic_1164.all;packageuse
本文标题:VHDL语法格式
链接地址:https://www.777doc.com/doc-4186753 .html