VHDL语法格式.docx

上传人:b****3 文档编号:4797625 上传时间:2022-12-09 格式:DOCX 页数:28 大小:52.30KB
下载 相关 举报
VHDL语法格式.docx_第1页
第1页 / 共28页
VHDL语法格式.docx_第2页
第2页 / 共28页
VHDL语法格式.docx_第3页
第3页 / 共28页
VHDL语法格式.docx_第4页
第4页 / 共28页
VHDL语法格式.docx_第5页
第5页 / 共28页
点击查看更多>>
下载资源
资源描述

VHDL语法格式.docx

《VHDL语法格式.docx》由会员分享,可在线阅读,更多相关《VHDL语法格式.docx(28页珍藏版)》请在冰豆网上搜索。

VHDL语法格式.docx

VHDL语法格式

VHDL语法格式

上篇基础元素

目录:

数据类型数据对象运算符语句基本程序结构电路描述方式

数据类型

预定义类型

bit

bit_victor

integer

std_logic

std_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,

表达式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

并行语句;--被保护的变量前需加上保留字guarded

endblock块标号;

带保护的块语句举例:

entitylatchis

port(d,clk:

inbit;

q,qb:

outbit

);

endlatch;

achetectirelatch_guardoflatchis

begin

b1:

block(clk=1)

begin

q<=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;

case语句--case语句中,条件值有3种形式:

值,值1|值2|...|值n,值TO值

--最后一行的顺序语句若为null,则有意引入锁存器

case条件表达式is

when条件值=>顺序语句;

......

whenothers=>顺序语句;

endcase;

for_loop语句[标号]:

for循环变量in值to值loop;

顺序语句;

endloop[标号];

时钟边沿描述

上升沿时钟eventand时钟=1|rising_edge(时钟)

下降沿时钟eventand时钟=0|falling_edge(时钟)

程序基本结构

--主程序与元件程序在同一文件中,

libraryieee;

use主程序

entity实体名is--实体名必须与文件名相同

port(端口声明;

);

endentitywork1;

architecturestrucofwork1is

[声明语句;]--常量,变量,信号,元件,函数等

begin

并行语句;

endarchitecturestruc;

电路描述方式

行为描述方式

以用状态机描述电路为典型

数据流(寄存器)描述方式

即用逻辑表达式描述电路

结构描述方式

以用元件复用的方式描述电路为典型

 

VHDL语法格式

下篇复合元素和状态机

元件----------1单文件元件

2多文件元件

函数----------3单文件函数

4多文件函数

过程----------5单文件过程

6多文件过程

moorl状态机--7二进程moorl状态机

8三进程moorl状态机

meaky状态机--9二进程mealy状态机

10三进程mealy状态机

状态机实例----11交通灯之一

12交通灯之二

附录----------13状态转移图

14用户库的格式和用法

单文件元件

--主程序与元件程序在同一文件中,

libraryieee;

use主程序

entitywork1is

port(r,s,t,u:

instd_logic;

v:

outstd_logic

);

endentitywork1;

architecturestrucofwork1is

componentym--将实体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;

begin

u1:

ymportmap(r,s,temp1);--元件例化

u2:

ymportmap(t,u,temp2);

u3:

hmportmap(temp1,temp2,v);

endarchitecturestruc;

--ym元件实体定义程序

libraryieee;

useymis

port(a,b:

instd_logic;

c:

outstd_logic

);

endentityym;

architectureym1ofymis

begin

c<=aandb;

endarchitectureym1;

--hm元件实体定义程序

libraryieee;

usehmis

port(a,b:

instd_logic;

c:

outstd_logic

);

endentityhm;

architecturehm1ofhmis

begin

c<=aorb;

endarchitecturehm1;

多文件元件

--主程序文件和定义元件的程序文件都要添加到工程中

--主程序文件,不需要声明用户库文件

libraryieee;

usezhu_mapis

port(r,s,t,u:

instd_logic;

v:

outstd_logic

);

endentityzhu_map;

architectureniuofzhu_mapis

componentym

port(a,b:

instd_logic;

c:

outstd_logic

);

endcomponentym;

componenthm

port(a,b:

instd_logic;

c:

outstd_logic

);

endcomponenthm;

signaltemp1,temp2:

std_logic;

begin

u1:

ymportmap(r,s,temp1);--元件例化

u2:

ymportmap(t,u,temp2);

u3:

hmportmap(temp1,temp2,v);

endarchitectureniu;

--定义元件实体的程序文件

--ym元件实体定义程序

libraryieee;

useymis

port(a,b:

instd_logic;

c:

outstd_logic

);

endentityym;

architectureym1ofymis

begin

c<=aandb;

endarchitectureym1;

--hm元件实体定义程序

libraryieee;

usehmis

port(a,b:

instd_logic;

c:

outstd_logic

);

endentityhm;

architecturehm1ofhmis

begin

c<=aorb;

endarchitecturehm1;

单文件函数

libraryieee;

usefuncis

port(din1,din2:

instd_logic_vector(0to3);

dout:

outstd_logic_vector(0to3)

);

endentity;

architectureaoffuncis

--定义函数

functionls_xj(d1,d2:

instd_logic_vector(0to3)

)returnstd_logic_vectoris

variabletemp:

std_logic_vector(0to3);

begin

temp:

=d1+d2;

returntemp;

endfunction;

--定义函数结束

begin

dout<=ls_xj(din1,din2);--调用函数

endarchitecture;

多文件函数

--主程序文件和定义函数的程序文件都要添加到工程中

--主程序文件,必须声明用户库文件

libraryieee;

use--作为用户库

entityzhu_funcis

port(din1,din2:

instd_logic_vector(0to3);

dout:

outstd_logic_vector(0to3)

);

end;

architectureniuofzhu_funcis

begin

dout<=ls_xj(din1,din2);--调用函数

end;

--定义函数的文件

libraryieee;

useuse_funcis--声明

functionls_xj(d1,d2:

instd_logic_vector(0to3)

)returnstd_logic_vector;

enduse_func;

packagebodyuse_funcis--程序体

functionls_xj(d1,d2:

instd_logic_vector(0to3)

)returnstd_logic_vectoris

variabletemp:

std_logic_vector(0to3);

begin

temp:

=d1andd2;

returntemp;

endfunction;

enduse_func;

单文件过程

libraryieee;

usecall_proceis

port(d1:

inintegerrange0to31;

d2:

inintegerrange0to31;

fout:

outintegerrange0to31);

end;

architectureaofcall_proceis

--过程定义

procedurejfq(din1,din2:

inintegerrange0to31;

dout:

outintegerrange0to31

)is

begin

dout:

=din1+din2;

end;

--过程定义结束

begin

process(d1,d2)

variablefo:

integerrange0to31;

begin

jfq(d1,d2,fo);--调用过程

fout<=fo;

endprocess;

end;

多文件过程

--主程序文件和定义过程的程序文件都要添加到工程中

--主程序文件,必须声明用户库文件

libraryieee;

use--作为用户库

entityzhu_procis

port(d1,d2:

inintegerrange0to31;

fout:

outintegerrange0to31

);

end;

architectureniuofzhu_procis

begin

process(d1,d2)

variablefo:

integerrange0to31;

begin

jfq(d1,d2,fo);--调用过程

fout<=fo;

endprocess;

end;

--定义过程的文件

libraryieee;

useuse_procis--声明

procedurejfq(din1:

inintegerrange0to31;

din2:

inintegerrange0to31;

dout:

outintegerrange0to31

);

enduse_proc;

packagebodyuse_procis--程序体

procedurejfq(din1,din2:

inintegerrange0to31;

dout:

outintegerrange0to31

)is

begin

dout:

=din1+din2;

endjfq;

enduse_proc;

二进程moorl状态机

libraryieee;

usemoorl_1is

port(reset:

instd_logic;

clock:

instd_logic;

din:

instd_logic;

dout:

outstd_logic_vector(2downto0)

);

endentity;

architecturestatemachineofmoorl_1is

typestate_typeis(s0,s1,s2,s3);

signalstate:

state_type;

begin

process(reset,clock)--变换状态

begin

ifreset='1'then

state<=s0;

elsifrising_edge(clock)then

casestateis

whens0=>ifdin='1'then

state<=s1;

endif;

whens1=>ifdin='1'then

state<=s2;

endif;

whens2=>ifdin='1'then

state<=s3;

endif;

whens3=>ifdin='1'then

state<=s0;

else

state<=s1;

endif;

endcase;

endif;

endprocess;

process(state)--输出

begin

casestateis

whens0=>dout<="001";

whens1=>dout<="011";

whens2=>dout<="101";

whens3=>dout<="111";

endcase;

endprocess;

end;

三进程moorl状态机

libraryieee;

usemoorl_2is

port(reset:

instd_logic;

clock:

instd_logic;

din:

instd_logic;

dout:

outstd_logic_vector(2downto0)

);

endentity;

architecturestatemachineofmoorl_2is

typestate_typeis(s0,s1,s2,s3);

signalpresentstate:

state_type;

signalnextstate:

state_type;

begin

process(reset,clock)--更新当前状态

begin

ifreset='1'then

presentstate<=s0;

elsifrising_edge(clock)then

presentstate<=nextstate;

endif;

endprocess;

process(presentstate,din)--生成下一个状态

begin

casepresentstateis

whens0=>ifdin='1'then

nextstate<=s1;

else

nextstate<=s0;

endif;

--dout<="001";

whens1=>ifdin='1'then

nextstate<=s2;

else

nextstate<=s1;

endif;

--dout<="011";

whens2=>ifdin='1'then

nextstate<=s3;

else

nextstate<=s2;

endif;

--dout<="101";

whens3=>ifdin='1'then

nextstate<=s0;

else

nextstate<=s1;

--dout<="111";

endif;

endcase;

endprocess;

process(presentstate)--输出

begin

casepresentstateis

whens0=>dout<="001";

whens1=>dout<="011";

whens2=>dout<="101";

whens3=>dout<="111";

endcase;

endprocess;

end;

二进程mealy状态机

libraryieee;

usemealy_1is

port(reset:

instd_logic;

clock:

instd_logic;

din:

instd_logic;

dout:

outstd_logic_vector(2downto0)

);

endentity;

architecturestatemachineofmealy_1is

typestate_typeis(s0,s1,s2,s3);

signalstate:

state_type;

begin

process(reset,clock)--变换状态

begin

ifrese

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1