码迷,mamicode.com
首页 > 其他好文 > 详细

Shift Register

时间:2014-10-02 22:31:34      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   sp   div   c   on   amp   r   

/***************************************************

/  Shift Register module

/  Programing by seongki

***************************************************/

module Shift_Register_4_beh(output reg [3:0] A_par,input [3:0] I_par, input s1,s0, MSB_in,LSB_in,CLK,Clear);

always@(posedge CLK,negedge Clear)

if(~Clear)A_par<=4‘b0000;

else

case({s1,s0})

2‘b00:A_par<=I_par;

2‘b01:A_par<={MSB_in,I_par[3:1]};

2‘b10:A_par<={I_par[2:0],LSB_in};

2‘b11:A_par<=I_par;

endcase

endmodule

 // testbench

`timescale 1ns/1ns

module tb_Shift_Register_4_beh;

reg [3:0] I_par;

reg s1,s0,MSB_in,LSB_in,CLK,Clear;

wire [3:0] A_par;

 

Shift_Register_4_beh test1(A_par,I_par,s1,s0, MSB_in,LSB_in,CLK,Clear);

 

initial

  begin

    I_par=4‘b1111;

    Clear=0; MSB_in=0; LSB_in=0; CLK=0; s1=0; s0=0;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1; 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=0; s0=0;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=0; s0=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=1; s0=0;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

 

    #10 Clear=1; MSB_in=0; LSB_in=0; CLK=0; s1=1; s0=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

    #10 CLK=1;

    #10 CLK=0;

 

  end

endmodule

 

bubuko.com,布布扣

Shift Register

标签:io   os   ar   sp   div   c   on   amp   r   

原文地址:http://www.cnblogs.com/capark/p/4004474.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!