2012年10月18日 星期四

P6-10 方塊程序指定4-bit Register


//P6-10 方塊程序指定4-bit Register
//KEY[0]--> Clock  會有Bounce 問題
//De-bounce  需改成CLOCK --> Clock_50 (50MHZ) 1sec Tirgger 一次


module Reg_bpa(CLOCK_50,SW, KEY, LEDR, LEDG );

input  [17:0] SW; // toggle switches
input  [7:0]  KEY;
input  CLOCK_50;    //Clock 50MHZ
output [17:0] LEDR; // red LEDs
output [7:0]  LEDG; // green LEDs


    /*
output [3:0] Qout;
input CLK, RESET;
input Din;
*/
//wire [3:0] Qout  disable , reg[3:0]Qout;
wire  CLK;
wire  RESET;
reg [3:0] Qout;

//assign to DE2-70 hardware     

    assign CLK = KEY[0];
    assign RESET= KEY[1];
    assign Din =SW[0];
   

    // negedge RESET --> if (!RESET)
    // posedge RESET --> if (RESET)
always @ (posedge CLK or negedge RESET)
//Positive edge CLK and asynchronous RESET
if (!RESET)
Qout = 4'b0000;
else
begin
Qout[0] = Din;
Qout[1] = Qout[0];
Qout[2] = Qout[1];
Qout[3] = Qout[2];
end

assign LEDG[3:0]=Qout;

endmodule




/*
//--------------------------------------------------
//4-bit register for Blocking Procedural Assignment
//Filename : reg_bpa.v
//--------------------------------------------------
module reg4_bpa(Qout, CLK, RESET, Din);
output [3:0] Qout;
input CLK, RESET;
input Din;

reg [3:0] Qout;


always @ (posedge CLK or posedge RESET)
//Positive edge CLK and asynchronous RESET
 if (RESET)
   Qout = 4'b0000;
 else
  begin
   Qout[0] = Din;
   Qout[1] = Qout[0];
   Qout[2] = Qout[1];
   Qout[3] = Qout[2];
  end
endmodule
*/

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...