题解 | #自动贩售机1#

自动贩售机1

https://www.nowcoder.com/practice/dcf59e6c51f6489093495acb1bc34dd8

`timescale 1ns/1ns
module seller1(
	input wire clk  ,
	input wire rst  ,
	input wire d1 ,
	input wire d2 ,
	input wire d3 ,
	
	output reg out1,
	output reg [1:0]out2
);
//*************code***********//
reg		[2:0]	cnt ;
always @(posedge clk or negedge rst) begin
	if(!rst) begin
		cnt <= 3'b0 ;
	end
	else if(d1) begin
		cnt <= cnt +3'b1 ;
	end
	else if(d2) begin
		cnt <= cnt + 3'd2 ;
	end
	else if(d3) begin
		cnt <= cnt +3'd4 ;
	end
	else if(cnt >= 3'd3) begin
		cnt <= 3'd0 ;
	end
end
always @(posedge clk or negedge rst) begin
	if(!rst) begin
		out1 <= 1'b0 ;
	end
	else if(cnt >=3'd3) begin
		out1 <=1'b1 ;
	end
	else begin
		out1 <= 1'b0 ;
	end
end
always @(posedge clk or negedge rst) begin
	if(!rst) begin
		out2 <= 2'b0 ;
	end
	else if(cnt >=3'd3) begin
		out2 <=cnt - 3'd3 ;
	end
	else begin
		out2 <= 1'b0 ;
	end
end

//*************code***********//
endmodule

全部评论

相关推荐

07-09 19:25
门头沟学院 Java
这是要把每一个投校招的都开盒吗?
26届之耻将大局逆转:裁人的时候一次性追回餐费
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 14:10
啊啊啊啊好幸福,妈妈是我找工作发疯前的一束光
榕城小榕树:你是我见过最幸福的牛客男孩
点赞 评论 收藏
分享
06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
不亏是提前批,神仙打架,鼠鼠不配了
站队站对牛:现在92都报工艺岗了
投递韶音科技等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务