集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 3504|回复: 8

verilog8位数的串入并出 代码

[复制链接]
interig 发表于 2010-6-28 00:11:48 | 显示全部楼层 |阅读模式
吐血求 verilog8位数的串入并出 代码<br>
急需啊 达人给指导下吧
HANG 发表于 2010-6-28 01:48:28 | 显示全部楼层
大家来瞧瞧吧 没时间拉<br>
偶的学分呀
       

       
AAT 发表于 2010-6-28 02:47:47 | 显示全部楼层
呵呵,来瞧瞧,可我没有!
VVC 发表于 2010-6-28 04:07:56 | 显示全部楼层
我想串入并出该是这样的:有一个&nbsp;&nbsp;输入量,然后通过左移运算或者拼接&nbsp;&nbsp;把它的值一次次地赋给&nbsp;&nbsp;reg[7:0]的最后一位,八次搞完后就把reg[7:0]的值输出就OK了。
CHANG 发表于 2010-6-28 05:44:19 | 显示全部楼层
我是这样写的,不知道对不对?麻烦大家看看,谢谢!

//Serial to Parral
//size = 8

module S2P(clk,in,out,flag);
    input clk;
    input in;
    output [7:0] out;
    reg [7:0] out;
    output flag;
    reg flag;
   
    integer count;
    reg [7:0] temp;
    //count = 0;
    initial
        begin
        count = 0;
        temp[0] &lt;= 0;
        temp[1] &lt;= 0;
        temp[2] &lt;= 0;
        temp[3] &lt;= 0;
        temp[4] &lt;= 0;
        temp[5] &lt;= 0;
        temp[6] &lt;= 0;
        temp[7] &lt;= 0;
        end
    always @(posedge clk)
            begin
                //begin
                temp[0] &lt;= temp[1];
                temp[1] &lt;= temp[2];
                temp[2] &lt;= temp[3];
                temp[3] &lt;= temp[4];
                temp[4] &lt;= temp[5];
                temp[5] &lt;= temp[6];
                temp[6] &lt;= temp[7];
                temp[7] &lt;= in;
                //temp &lt;&lt; in;
                count = count + 1;
                //end
               
                if(count == 8)
                    begin
                    flag &lt;= 1;
                    count = 0;
                    end
                else
                    flag &lt;= 0;
               
                if(flag == 1)
                    begin
                    out[0] &lt;= temp[0];
                    out[1] &lt;= temp[1];
                    out[2] &lt;= temp[2];
                    out[3] &lt;= temp[3];
                    out[4] &lt;= temp[4];
                    out[5] &lt;= temp[5];
                    out[6] &lt;= temp[6];
                    out[7] &lt;= temp[7];
                    end
            end
endmodule
longtime 发表于 2010-6-28 06:37:40 | 显示全部楼层
我新手笔,这是我想法,不知道对不对<br>
<br>
将串行数据一次付给并行data[0]到data[7],每付完一次,串行数据移一位,就可以了吧<br>

       
HDL 发表于 2010-6-28 08:36:46 | 显示全部楼层
看一下这个,应该有用<br>
<br>
<br>
module tb_transform; <br>
<br>
wire clk, rst, sp, Ds;<br>
wire [7:0] Dp;<br>
<br>
test_signal test (clk, rst, sp, Ds, Dp);<br>
transform transform (clk, rst, sp, Ds, Dp);<br>
&nbsp;&nbsp;<br>
endmodule <br>
<br>
<br>
<br>
<br>
<br>
<br>
module transform (clk, rst, sp, Ds, Dp);<br>
inout Ds;<br>
inout [7:0] Dp;<br>
input clk, rst, sp;<br>
<br>
reg Dst,sign;<br>
reg [7:0] Dpt;<br>
reg [3:0] counter1, counter2;<br>
<br>
assign Ds=sp?1'bz
       
st;<br>
assign Dp=!sp?8'bz
       
pt;&nbsp;&nbsp;<br>
<br>
always @ (posedge clk or negedge rst)<br>
&nbsp; &nbsp; &nbsp; &nbsp; if(!rst)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //寄存器初始化<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dpt&lt;=0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dst&lt;=0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sign&lt;=1;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter1&lt;=0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter2&lt;=0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>
&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; if(sp&amp;&amp;(counter1&lt;=7))//串转并<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; Dpt[0]&lt;=Ds;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//将串型输入赋给临时并型寄存器的最低位<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; Dpt[7:1]&lt;=Dpt[6:0];&nbsp; &nbsp;//临时并型寄存器的低7位向左移一位。<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; counter1&lt;=counter1+1;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; end<br>
&nbsp; &nbsp; &nbsp; &nbsp; else if(!sp&amp;&amp;sign)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//先于转换,将并型输入信号暂存到dpt中,并将sign赋0,以防反复向dpt赋值。<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; begin<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; Dpt&lt;=Dp;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; sign&lt;=0;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; end<br>
&nbsp; &nbsp; &nbsp; &nbsp; else if(!sp&amp;&amp;(counter2&lt;=7))//并转串<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; begin&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; <br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Dpt[7:1]&lt;=Dpt[6:0];&nbsp;&nbsp;//临时并型寄存器的低7位向左移一位。<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Dst&lt;=Dpt[7];&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//把最高位赋给输出。<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; counter2&lt;=counter2+1;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; end&nbsp; &nbsp;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<br>
endmodule
ngtim 发表于 2010-6-28 10:08:59 | 显示全部楼层
module wyp_8(dir,rdn,cp,q);<br>
input&nbsp; &nbsp;&nbsp; &nbsp; dir,rdn,cp;<br>
output[7:0] q;<br>
reg[7:0]&nbsp; &nbsp; q;<br>
always@(negedge cp or negedge rdn)<br>
begin<br>
&nbsp;&nbsp;if(~rdn)&nbsp;&nbsp;q=0;<br>
&nbsp;&nbsp;else begin q=q&gt;&gt;1;q[7]=dir;end<br>
end<br>
endmodule
encounter 发表于 2010-6-28 10:22:38 | 显示全部楼层
这是我写的,呵呵<br>
<br>
/*&nbsp; &nbsp;=========== 串-并转换 ===============&nbsp;&nbsp;*/<br>
<br>
module s_p(bits,clk,data_out);<br>
<br>
input clk,bits;<br>
output [7:0] data_out;<br>
<br>
reg [7:0] state;<br>
reg [7:0] data_out;<br>
<br>
<br>
parameter bit1=8'00000001,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//独热码定义状态机<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; bit2=8'00000010,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;bit3=8'00000100,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;bit4=8'00001000,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;bit5=8'00010000,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;bit6=8'00100000,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;bit7=8'01000000,<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;bit8=8'10000000;<br>
<br>
always @(posedge clk or negedge reset) begin&nbsp; &nbsp; //主程序开始<br>
&nbsp;&nbsp;if(~reset) state=bit1;<br>
&nbsp;&nbsp;<br>
&nbsp; &nbsp;else<br>
&nbsp; &nbsp;&nbsp;&nbsp;case(state)<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; bit1: begin<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;data_out[0]=bits;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;state=(state&lt;&lt;1);<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; end<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; bit2: begin<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;data_out[1]=bits;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;state=(state&lt;&lt;1);<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; end<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; bit3: begin<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;data_out[2]=bits;<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;state=(state&lt;&lt;1);<br>
&nbsp; &nbsp;&nbsp; &nbsp; end<br>
<br>
&nbsp; &nbsp;&nbsp; &nbsp; bit4: begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;data_out[3]=bits;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state=(state&lt;&lt;1);<br>
&nbsp; &nbsp;&nbsp; &nbsp; end<br>
<br>
&nbsp; &nbsp;&nbsp; &nbsp; bit5: begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;data_out[4]=bits;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;state=(state&lt;&lt;1);<br>
&nbsp; &nbsp;&nbsp; &nbsp; end<br>
<br>
&nbsp; &nbsp;&nbsp; &nbsp; bit6: begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; data_out[5]=bits;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; state=(state&lt;&lt;1);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end<br>
<br>
&nbsp; &nbsp;&nbsp; &nbsp; bit7: begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; data_out[6]=bits;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; state=(state&lt;&lt;1);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end<br>
&nbsp; &nbsp;&nbsp; &nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp; bit8:begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; data_out[7]=bits;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; state=(state&lt;&lt;1);<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end<br>
&nbsp; &nbsp;&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp; default:<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; state=bit1;<br>
&nbsp; &nbsp;&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp;&nbsp;endcase&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;<br>
end<br>
<br>
endmodule
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 11:06 , Processed in 0.066592 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表