2014年6月10日 星期二

The SISO SIPO PISO PIPO Shift Register ---適用於DE2-70

The SISO SIPO PISO PIPO  Shift Register ---適用於DE2-70 


Block diagram of 8-bit shift register









module Par_2_Ser(  //適用於DE2-70 的程式

 input [17:0]SW,
 input [3:0] KEY,
 input  CLOCK_50,
 output [17:0] LEDR,
 output [7:0] LEDG,
 output [6:0] HEX0,
 output [6:0] HEX1,
 output [6:0] HEX2,
 output [6:0] HEX3,
 output [6:0] HEX4,
 output [6:0] HEX5,
 output [6:0] HEX6,
 output [6:0] HEX7
 );

assign HEX0=7'b111_1111;  //off 7-segment Display
assign HEX1=7'b111_1111;
assign HEX2=7'b111_1111;
assign HEX3=7'b111_1111;
assign HEX4=7'b111_1111;
assign HEX5=7'b111_1111;
assign HEX6=7'b111_1111;
assign HEX7=7'b111_1111;
// assign LEDR[17:0]=SW[17:0];  //SW status =>LEDR
assign LEDR[17:15]=SW[17:15];  //SW status =>LEDR
//Main_Par_2_Ser(sin,clk,load, fun, sout, pout, pin);
//clk_div_1hz(clk_in , Reset, clk_out);
wire clk_1hz;
assign LEDG[0]=clk_1hz;

clk_div_1hz u1(CLOCK_50, KEY[0], clk_1hz);

Main_Par_2_Ser u0(KEY[0],KEY[1],clk_1hz,SW[17],SW[16:15],LEDG[7],LEDR[7:0],SW[7:0]);


endmodule



module Main_Par_2_Ser(reset, sin,clk,load, fun, sout, pout, pin);
    input reset ,sin,clk,load;
    input [1:0] fun;
    output reg sout;
    output reg [7:0] pout;
    input [7:0] pin;
   // reg [7:0]a;

// always@(clk,load,fun,sin,pin) begin
always@(posedge clk) begin
if (!reset) begin
   pout=8'b0000_0000;
   sout=1'b0;
   end
else if(fun[1:0]==2'b00)    //SISO Operation 
 begin
 if(clk==1)   //clk==1
begin
  if(load==0)   //load=0  clk==1
     begin
/*
sout=a[0]; 
a[0]=a[1];
a[1]=a[2];
a[2]=a[3];
a[3]=a[4];
a[4]=a[5];
a[5]=a[6];
a[6]=a[7];
a[7]=sin;
*/
sout=pout[0]; 
pout[0]=pout[1];
pout[1]=pout[2];
pout[2]=pout[3];
pout[3]=pout[4];
pout[4]=pout[5];
pout[5]=pout[6];
pout[6]=pout[7];
pout[7]=sin;
end
else  //clk==1 load==1
       sout=sout;
end
  else   //clk==0
  sout=sout;
 end 

//============================ 
else if(fun[1:0]==2'b01)    //SIPO Operation
begin
if(clk==1)
   begin
if(load==0)
begin               //clk==1 load==0
pout[0]=pout[1];  //SIPO Operation
pout[1]=pout[2];
pout[2]=pout[3];
pout[3]=pout[4];
pout[4]=pout[5];
pout[5]=pout[6];
pout[6]=pout[7];
pout[7]=sin;
end
else
pout=pout;  //clk==1 load==1
end
else   //clk==0  
pout=pout;
end

//============================  
else if(fun[1:0]==2'b10) //PISO Operation
begin
if(clk==1)
begin
if(load==1)   //clk==1 load=1
//a=pin;   //8bit load into a
pout=pin;   //8bit load into a
else   //clk==1 load==0 
   begin
/*
sout=a[0];  //PISO Operation
a[0]=a[1];
a[1]=a[2];
a[2]=a[3];
a[3]=a[4];
a[4]=a[5];
a[5]=a[6];
a[6]=a[7];
a[7]=0;
*/
sout=pout[0];  //PISO Operation
pout[0]=pout[1];
pout[1]=pout[2];
pout[2]=pout[3];
pout[3]=pout[4];
pout[4]=pout[5];
pout[5]=pout[6];
pout[6]=pout[7];
pout[7]=0;
end
end
else 
sout=sout;   //clk==0  No-change
end

//============================
else if(fun[1:0]==2'b11)   //PIPO Operation
begin
if(clk==1)
begin
if(load==1)
   pout=pin;   //clk==1 load==1  Load Data into 
else
   pout=pout;  //clk==1 load==0  No-change
end
pout=pout;  //clk==0          No-change
end
  end

endmodule



module clk_div_1hz(clk_in , Reset, clk_out);
input clk_in ;
input Reset;
output reg  clk_out;

integer i;
always@(posedge clk_in or negedge Reset) begin
 if (!Reset) begin
   i=0;
   clk_out=0;
   end
 else begin
    i= i+1 ;
    if (i>=24_999_999) begin
        clk_out  = ~clk_out;
        i=0;
       end
    end    
end            

endmodule

沒有留言:

張貼留言

Node-Red & ModeBus FC=1

Node-Red & ModeBus FC=1 write address=0..7   8bits read address=16..23 8bits  [{"id":"cf7c1253d4d997dd","type&q...