2012年10月8日 星期一

P4-17 2bit比較器配合DE2-70修改後程式



只要import DE2-70 pin assignments 即可執行

//=======================================

module comp4bit (SW, LEDR, LEDG);
input [17:0] SW; // toggle switches
output [17:0] LEDR; // red   LEDs  
  output [7:0] LEDG; // green LEDs
  
wire eq2,gt2,lt2;    //comout[2]:great than, comout[1]:equal
                        //comout[0]:less than
    wire [1:0] a, b;    //input data 
   
    //mapping to hardware 
    assign LEDR = SW;
assign a = SW[1:0];
assign b = SW[9:8];
    
   
    wire el,gl,ll ; //LSB output equal->el , great than->gl  , less than->ll
    wire eh,gh,lh ; //MSB output equal , great than , less than
wire gla,lla ;

and (gla,gl,eh);
and (lla,ll,eh);

//Instantiated by name
comp1_g UUT1(.eq(el),.gt(gl),.lt(ll),.a(a[0]),.b(b[0]));
comp1_g UUT2(.eq(eh),.gt(gh),.lt(lh),.a(a[1]),.b(b[1]));

//and or gates are instantabtiated

and (eq2,el,eh);   //equal
or(gt2,gla,gh);  //great than
or(lt2,lla,lh);  //less than

assign LEDG[1]=eq2;
assign LEDG[0]=lt2;
assign LEDG[2]=gt2;


endmodule
//===========================================


// 1-bit comparater  gate-level 
//filename : comp1_g.v
module comp1_g( a, b,eq,gt,lt);   //eq =EQUAL gt:Great Than  lt :Less than 

input a,b;
output  eq,gt,lt;   

wire an,bn,a0b0,a1b1 ;  //internal signal declare

not(an,a);
not(bn,b);
and(a1b1,a,b);
nor(a0b0,a,b);


or(eq,a0b0,a1b1);   //eq
and(gt,a,bn);     //gt
and(lt,an,b);    //lt

endmodule


沒有留言:

張貼留言

習題解答 (5/6)

  第五章 習題解答 一、 錯誤偵測技術 1. 何謂循環冗餘檢查法 (CRC)? 是一種根據傳輸資料產生簡短固定位數校驗碼的演算法。發送端將資料除以一個特定的多項式,得到的「餘數」即為 CRC 碼並隨資料發送;接收端以同樣多項式除之,若餘數為 0 則代表資料傳輸正確。 2. 何...