2014年11月22日 星期六

將課本範例 套用到 DE2-70 實驗版上(1)


將課本範例 套用到DE2-70 實驗版上

¡

module comp4bit (SW, LEDR, LEDG);
¡input [17:0] SW; // toggle switches
¡output [17:0] LEDR; // red    LEDs
¡output [7:0] LEDG; // green LEDs
¡wire  原來輸出變數 
¡wire 原來輸入變數
¡assign LEDR = SW;
¡assign  輸入變數= SW[x:x];
¡assign  輸入變數= SW[x:x];

 原來課本程式本體


¡ assign LEDG[x]=輸出變數;
¡ assign LEDG[x]=輸出變數;
¡ assign LEDG[x]=輸出變數;
¡ endmodule



2bit比較器為例
module comp4bit (SW, LEDR, LEDG);
input [17:0] SW; // toggle switches

output [17:0] LEDR; // red     
  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
¡

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...