题解 | #数据串转并电路#

数据串转并电路

https://www.nowcoder.com/practice/6134dc3c8d0741d08eb522542913583d

`timescale 1ns/1ns

module s_to_p(
	input 				clk 		,   
	input 				rst_n		,
	input				valid_a		,
	input	 			data_a		,
 
 	output	reg 		ready_a		,
 	output	reg			valid_b		,
	output  reg [5:0] 	data_b
);

reg [5:0] data_reg;
reg [2:0] data_cnt;

always @ (posedge clk or negedge rst_n)
begin
if (!rst_n) ready_a<=1'd0;
else ready_a<=1'd1;
end

always @ (posedge clk or negedge rst_n)
begin
if (!rst_n) data_cnt<=3'd0;
else if (valid_a&&ready_a) data_cnt<=(data_cnt==3'd5)?3'd0:(data_cnt+1'd1);
end

always @ (posedge clk or negedge rst_n)
begin
if (!rst_n) data_reg<=6'd0;
else if (valid_a&&ready_a) data_reg<={data_a,data_reg[5:1]};
end

always @ (posedge clk or negedge rst_n)
begin
if (!rst_n) begin valid_b<=1'd0; data_b<=6'd0;end
else if (data_cnt==3'd5) begin valid_b<=1'd1;data_b<={data_a,data_reg[5:1]}; end
else valid_b<=1'd0;
end


endmodule

全部评论

相关推荐

10-14 21:44
门头沟学院 Java
九门空城:10000月薪+1500房补+中午20餐补+晚饭免费 上下班班车免费通勤 就问你来不来吧
投递京东等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务