题解 | #自动贩售机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] money;
always@(posedge clk or negedge rst) begin
	if(!rst) money <= 0;
	else money <= (money>=3'd3)? 0 : money + {d3,d2,d1};
end
always@(posedge clk or negedge rst) begin
	if(!rst) begin
		out1 <= 0;
		out2 <= 0;
	end
	else case(money)
		3'b011: begin 
			out1 <= 1;
			out2 <= 0;
		end
		3'b100: begin 
			out1 <= 1;
			out2 <= 1;
		end
		3'b101: begin 
			out1 <= 1;
			out2 <= 2;
		end
		3'b110: begin 
			out1 <= 1;
			out2 <= 3;
		end
		default: begin
			out1 <= 0;
			out2 <= 0;
		end
		endcase
end
//*************code***********//
endmodule

全部评论

相关推荐

点赞 评论 收藏
分享
迟缓的斜杠青年巴比Q了:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
感觉今年拿到大厂实习offer的人很多,光是身边同学室友都是好几个offer。由此可见,秋招得有多卷
小浪_Coding:必须卷的起飞, 应该比25更卷一点, 25已经是哀声一片了, 26会更难一点, 现在还有`很多25未找到的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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