2012年11月20日 星期二

LAB02 1-LED Flashing , 3-LED Shifting

LAB02 1-LED  Flash , 3-LED Shifting  適用於DE2-70




module mix_module (CLOCK_27,SW, KEY, LEDR, LEDG );

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

/* (CLK, RSTn, Flash_LED, Run_LED); */
     wire CLK;
wire RSTn;
wire Flash_LED;
wire [2:0]Run_LED;
 
assign CLK=CLOCK_27;
assign RSTn=KEY[0];
assign LEDG[0]=Flash_LED;
assign LEDG[7:5]=Run_LED;
 
/**********************************/
 
 
flash_module U1
(
    .CLK( CLK ),
    .RSTn( RSTn ),
 .LED_Out( Flash_LED ) 
);
 
/**********************************/

 
run_module U2
(
    .CLK( CLK ),
 .RSTn( RSTn ),
 .LED_Out( Run_LED )
);
 
/***********************************/
 

endmodule



module run_module 
(
    CLK, RSTn, LED_Out
);
    
input CLK;
input RSTn;
output [2:0]LED_Out;
 
/**************************/
 
parameter T1MS = 15'd19_999;
 
/**************************/
 
reg [14:0]Count1;
 
always @ ( posedge CLK  or negedge RSTn )
    if( !RSTn )
     Count1 <= 15'd0;
 else if( Count1 == T1MS )
     Count1 <= 15'd0;
 else 
     Count1 <= Count1 + 1'b1;

/*****************************************/
reg [9:0]Count_MS;
always @ ( posedge CLK or negedge RSTn )
    if( !RSTn )
     Count_MS <= 10'd0;
 else if( Count_MS == 10'd100 )
     Count_MS <= 10'd0;
 else if( Count1 == T1MS )
     Count_MS <= Count_MS + 1'b1;
/*********************************/
 
reg [2:0]rLED_Out;
 
always @ ( posedge CLK or negedge RSTn )
    if( !RSTn )
     rLED_Out <= 3'b001;
 else if( Count_MS == 10'd100 )
     begin
         if( rLED_Out == 3'b000 )
       rLED_Out <= 3'b001;
      else
             rLED_Out <= { rLED_Out[1:0], 1'b0 };
  end
/*****************************/
 
assign LED_Out = rLED_Out;
 
/*****************************/
 


endmodule


module flash_module
(
    CLK, RSTn, LED_Out
);

     input CLK;
input RSTn;
output LED_Out;
 
/*********************************/
 
parameter T50MS = 20'd999_999;
 
/********************************/
 
reg [19:0]Count1;  
 
always @ ( posedge CLK or negedge RSTn )
    if( !RSTn )
            Count1 <= 20'd0;
 else if( Count1 == T50MS )
     Count1 <= 20'd0;
    else
     Count1 <= Count1 + 1'b1;
/*********************************/
reg rLED_Out;
always @ ( posedge CLK or negedge RSTn )
   if( !RSTn )
    rLED_Out <= 1'b0;
else if( Count1 == T50MS )  //100???????
    rLED_Out <= ~rLED_Out;
 
    /*********************************/

assign LED_Out = rLED_Out;
 
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...