六、FPGA设计之并转串设计

来源:互联网 发布:linux 查看文本命令 编辑:程序博客网 时间:2024/06/07 00:02
module p_to_s(clk,rst_n,din,dout);
            input clk;
            input rst_n;
            input[7:0]din;
            output dout;
            
            reg[3:0]counter;
            reg[7:0]buff;
            reg dout;
            
            
            
            always@(posedge clk or negedge rst_n)
                   if(rst_n==1'b0)
                      counter<=4'd0;
                   else if(counter==8'd8)
                      counter<=4'd0;
                   else
                      counter<=counter+1;
            
            
            
            always@(posedge clk or negedge rst_n)
                     begin
                        if(rst_n==1'b0)
                           buff<=8'd0;
                        else
                          begin
                             if(counter==4'd0)
                                buff<=din;
                             else
                                buff<=(buff<<1);
                          end
                     end


            always@(posedge clk or negedge rst_n)
                    if(rst_n==1'b0)
                        dout<=1'b0;
                    else
                        dout<=buff[7];
                       

endmodule



0 0
原创粉丝点击