看一下这个,应该有用<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>
<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; <br>
<br>
always @ (posedge clk or negedge rst)<br>
if(!rst) //寄存器初始化<br>
begin<br>
Dpt<=0;<br>
Dst<=0;<br>
sign<=1;<br>
counter1<=0;<br>
counter2<=0;<br>
end<br>
else if(sp&&(counter1<=7))//串转并<br>
begin<br>
Dpt[0]<=Ds; //将串型输入赋给临时并型寄存器的最低位<br>
Dpt[7:1]<=Dpt[6:0]; //临时并型寄存器的低7位向左移一位。<br>
counter1<=counter1+1;<br>
end<br>
else if(!sp&&sign) //先于转换,将并型输入信号暂存到dpt中,并将sign赋0,以防反复向dpt赋值。<br>
begin<br>
Dpt<=Dp;<br>
sign<=0;<br>
end<br>
else if(!sp&&(counter2<=7))//并转串<br>
begin <br>
Dpt[7:1]<=Dpt[6:0]; //临时并型寄存器的低7位向左移一位。<br>
Dst<=Dpt[7]; //把最高位赋给输出。<br>
counter2<=counter2+1;<br>
end <br>
<br>
endmodule |