欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

玩欧卡就用莱仕达V10方向盘欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 8515|回复: 1
收起左侧

vhdl语句中“type state is (st0,st1,st2,st3,st4,st5)”是什么意思?

[复制链接]
起名字最烦了 发表于 2012-7-8 01:44 | 显示全部楼层 |阅读模式
定义一个数据类型state具有6种状态st0,st1,st2,st3,st4,st5可以像定义其他类型一样定义这种数据类型,一半用于状态机
 楼主| 起名字最烦了 发表于 2012-7-8 01:48 | 显示全部楼层
用户自定义类型是VHDL语言的一大特色。可由用户定义的数据类型有:枚举类型;整数和实数类型;数组类型;记录类型;子类型。
1、type(类型)定义语句
TYPE主要有三种描述格式:
1)整数类型描述
type <type_name> is array integer range <lower_limit> to <upper_limit>;
其中:type_name为类型名字,lower_limit为整数的下限值,upper_limit为整数的上限值。
【例3-16】type my_integer is integer range 0 to 9;
2)枚举类型描述
type <type_name> is (<string1>, <string2>, ...);
其中type_name为类型名字,<string>为字符串的名字。

【例3-17】9值系统的枚举类型语句
type std_logic is(‘U’,‘X’,‘0’,‘1’,‘Z’,‘W’,‘L’,‘H’,‘-’)

【例3-18】颜色枚举类型语句
type color is(blue,green,yellow, red);
枚举类型的编码方法:综合器自动实现枚举类型元素的编码,一般将第一个枚举量(最左边)编码为0,以后的依次加1。编码用位矢量表示 ,位矢量的长度将取所需表达的所有枚举元素的最小值。一种编码为: blue=“00”; green=“01”; yellow=“10”; red=“11”;
3)通用类型描述
type <type_name> is type <type_definition>;
其中type_name为类型名字,<type_defination>为类型的定义。

【例3-19】类型的声明语句
type byte is array(7 downto 0) of bit;
variable addend : byte;
type week is (sun, mon, tue, wed, thu, fri, sat);
type byte is array(7 downto 0) of bit;
type vector is array(3 downto 0) of byte;

【例3-20】限定数组的声明
type bit_vector is array(integer range <>) of bit;
variable my_vector:bit_vector (5 downto -5);
2、subtype(子类型)定义语句
SUBTYPE实现用户自定义数据子类型。SUBTYPE主要有三种描述格式:
1)整数子类型描述
subtype <subtype_name> is integer range <lower_limit> to <upper_limit>;

【例3-21】子类型的声明语句
subtype digits is integer range 0 to 9;
2)数组子类型描述
subtype <subtype_name> is array range <lower_limit> to <upper_limit>;
3)通用子类型描述
subtype <subtype_name> is subtype <subtype_definition>;
由subtype 语句定义的数据类型称为子类型。

【例3-22】子类型声明语句
bit_vector 类型定义如下:
type bit_vector is array (natural range <>) of bit;
如设计中只用16bit;可定义子类型如下:subtype my_vector is bit_vector(0 to 15);
注:子类型与基(父)类型具有相同的操作符和子程序。可以直接进行赋值操作。

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-4-17 04:47 , Processed in 0.029891 second(s), 7 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表