收藏 分享(赏)

CH5-资料型别与资料物件的宣告.ppt

上传人:weiwoduzun 文档编号:5683937 上传时间:2019-03-12 格式:PPT 页数:23 大小:859.50KB
下载 相关 举报
CH5-资料型别与资料物件的宣告.ppt_第1页
第1页 / 共23页
CH5-资料型别与资料物件的宣告.ppt_第2页
第2页 / 共23页
CH5-资料型别与资料物件的宣告.ppt_第3页
第3页 / 共23页
CH5-资料型别与资料物件的宣告.ppt_第4页
第4页 / 共23页
CH5-资料型别与资料物件的宣告.ppt_第5页
第5页 / 共23页
点击查看更多>>
资源描述

1、1,資料型別與資料物件的宣告,第五章,儒林圖書公司 TB061,VHDL數位電路設計實務教本 使用Quartus II,資料的型別,2,邏輯訊號 布林代數(Boolean) 位元(Bit) 標準邏輯(Std_Logic) 基本邏輯序列(Bit_Vector)與標準邏輯序列 內部訊號宣告(Signal),數值訊號 整數(Integer) 實數(Real) 列舉式(Enumeration)資料型別 陣列(Array)資料型別 記錄(Record )資料型別,邏輯訊號- Booleans & Bits,3,type bit is (0, 1); signal x,y,z: bit;x = 0;y =

2、 1;z = x and y;,type boolean is (false, true); variable A,B,C: boolean;C := not AC := A and BC := A or B,邏輯訊號- Standard Logic,4,library IEEE; use IEEE.std_logic_1164.all;,type std_logic is ( X - Forcing unknown0 - Forcing zero1 - Forcing oneZ - High impedanceW - Weak unknownL - Weak zeroH - Weak one

3、-); - Dont care,邏輯訊號-Bit_Vector & Std_Logic_Vector,5,Signal D:Std_Logic_Vector(3 downto 0); Signal Q:Std_Logic_Vector(3 downto 0); Q=D;,Signal D3,D2,D1,D0:Std_Logic; Signal Q3,Q2,Q1,Q0:Std_Logic; Q3=D3;Q2=D2;Q1=D1;Q0=D0;,邏輯訊號-SIGNAL,6,Signal指令是宣告電路內部自行使用的訊號,因為這類訊號沒有傳送到電路的外部界面,所以通常我們都是在架構(Architectur

4、e)中宣告它,而非在VHDL程式的單體(Entity)裡進行宣告。,. signal S0,S1 : std_logic; beginS0 = A nand B;S1 = S0 nand C;Y = S1 nand D; end a;,邏輯訊號-SIGNAL的分解與合併,7,Signal A:Std_Logic_vector(4 downto 0); Signal B,C:Std_Logic_vector(2 downto 0); Signal D:Std_Logic_vector(0 to 4); B=A(3 downto 1); D=A(4) ,數值訊號-Integer Data Type

5、,VHDL語言中的整數數值範圍 :( - 231 + 1 ) to ( + 231 - 1 )Example of Integer Data Type:Signal A:Integer; -32位元數值宣告Signal B,C:Integer range 0 to 7; - 3位元數值宣告Variable INT_S:Integer; -32位元數值宣告,8,數值訊號-無號整數(UNSIGNED)序列,Unsigned指令宣告,它同時具有邏輯和數值的特性,因此既可作邏輯處理又可作數值運算,9,Signal A:Std_logic; Signal B,C:Unsigned(3 downto 0)

6、; A=B(3) and B(2) or B(0) ; -邏輯處理C=B-1; -數值運算,數值訊號- Real Data Types,VHDL語言中的實數範圍:-1.0E38 to 1.0E38Example of Real Data Type:Signal A,B:Real;A=3.0 ; -需要表示成小數點型式B=1.5E15;,10,數值訊號- Enumerated Data Type,列舉式資料型別(Enumeration type)是一種集合種類的宣告,使用者可以使用一些有意義的名稱,將其定義成集合體的元素 。Example of Enumeration Data Type:Typ

7、e co_state IS (main_green, main_yellow, farm_green, farm_yellow);Type std_ulogic IS (U, X ,0, 1, Z, W, L ,H, -);Type week IS (Mon, Tue, Wed, Thu, Fri, Sat, Sun);,11,數值訊號- Array Data Type,陣列資料型別是由同一種資料型別所組成的資料型別 。 Example of Array Data Type:Type Byte IS Array(7 downto 0) of Bit;Type Word IS Array(31

8、Downto 0) of Bit;,12,Example (二維的ROM):Type ROM_table5x4 IS array (0 to 4, 0 to 3) of bit;Constant ROM_con: ROM_table5x4:=( (1,0,0,1),(0,1,0,1),(0,0,1,0),(1,0,0,1),(0,0,1,1) );,數值訊號-Record Data Type,記錄資料型別(Record types)與陣列資料型別(Array Types)最大的差異是在於記錄資料型別是由兩種或兩種以上資料型別所構成,它可視為族群元素集合體的宣告。Example of Recor

9、d Data Type:Type MU2 IS RecordDin,Dout: bit_vector(7 downto 0);S:bit;End Record;Signal X,Y:MU2;,13,資料物件,14,常數(Constants) 訊號(Signals) 變數(Variables) 別名(Aliases),資料物件-常數(Constants),在VHDL語言中,我們將固定值宣告成常數 ,它類以C語言中以#define來設定常數值的作法。 Example of Constants:Constant A: Std_logic_vector(3 downto 0):=“0011”;Cons

10、tant Width: Integer:=8;Constant PI : real := 3.1415926535897 ;,15,資料物件-訊號(Signals),訊號可以用來宣告所有元件內部的信號線或內接腳位 。Example of Signals:Signal A:Std_Logic_vector(4 downto 0); Signal temp: bit_vector(0 to 3);,16,資料物件-變數(Variables),An Object Whose Value May be Changed After Creation.Example of Variables:Variab

11、le temp: Std_logic:= 0;Variable temp: Std_logic_Vector( 3 downto 0);Variable A,B:Boolean:=False;,17,資料物件-別名(Aliases),在電路中,若有一條匯流排需要區分成數束不同的子線連接到各個地方去時,我們就可以將原來的母線分開來各自命名,宣告每一束子線並各給其一個別名(Aliases)。 Example of Aliases:Signal A_Bus: Std_Logic_Vector(31 downto 0); Alias Bank1 : Std_Logic_Vector(7 downto

12、0) IS A_Bus (31 downto 24);Alias Cal_D : Std_Logic_Vector(15 downto 0) IS A_Bus (23 downto 8);Alias Rank : Std_Logic_Vector(7 downto 0) IS A_Bus (7 downto 0);,18,運算子(Operators),19,邏輯運算子:not and or xor nand xnor 關係運算子:= /= = 算術運算子:+ (加) - (減) * (乘) / (除) *(次方) REM(求餘數運算) MOD(求模數) 數值運算子:SLA、SRA、SLL、SR

13、L、ROL、ROR、,運算子(Operators)- 邏輯運算子,20,library ieee; use ieee.std_logic_1164.all;ENTITY log_ex ISPORT( A,B :in std_logic_vector(0 to 3);Y :out std_logic_vector(0 to 3);Z :out std_logic); end log_ex;,architecture a of log_ex isbegin Y(0) = A(0) AND B(0) ;Y(1) = A(1) OR B(1) ;Y(2) = A(2) NOR B(2) ;Y(3) =

14、 A(3) XOR B(3) ;Z = (not A(0) nand B(0); end A;,Logic operators: not and or xor nand xnor,運算子(Operators)- 關係運算子,21,Relational operators: = , /= , , = Operands must be of the same type,library ieee; use ieee.std_logic_1164.all;ENTITY rel_ex IS PORT( A,B,C,D,E,F:in std_logic_vector(2 downto 0);Y: out

15、std_logic); end rel_ex;,architecture behavior of rel_ex is begin process(A,B,C,D,E,F)beginif(A=B) or (CD) and not(E=F) theny=1;elsey=0;end if; end process; end behavior;,運算子(Operators)- 算術運算子,22,Arith. operators: + (加) - (減) * (乘) / (除) *(次方),library IEEE; use IEEE.Std_logic_1164.all; use IEEE.Std_l

16、ogic_unsigned.all;entity arith_ex is port(A,B : in integer range 7 downto 0;C,D : out integer range 64 downto 0;E,F,G : out integer range 7 downto 0); end arith_ex;,architecture a of arith_ex is beginC = A * B; D = 4*2; E = 4 mod 2; F = 6/2; G = 11 REM 3; end a;,運算子(Operators)- 數值運算子,23,SLA,SRA,SLL,SRL,ROL,ROR,A sll 2 為 “01010100” A srl 3 為 “00010010” A sla 3 為 “10101111” A sra 2 為 “11100101” A rol 3 為 “10101100” A ror 5 為 “10101100”,

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

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报