题解 | #自动贩售机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
out1<=0;
out2<=0;
cnt<=0;
end
else begin
case({d3,d2,d1})
3'b001:cnt<=cnt+1;
3'b010:cnt<=cnt+2;
3'b100:cnt<=cnt+4;
default:cnt<=cnt;
endcase
if(cnt >= 3)begin
out1 <= 1;
out2 <= cnt - 3;
cnt <= 0;
end
else begin
out1 <= 0;
out2 <= 0;
end
end
end
// always @(posedge clk or negedge rst) begin
// if (!rst)begin
// cnt<=0;
// end
// else begin
// if (cnt>=3'd3)begin
// out1<=1;
// out2<=cnt-3'd3;
// cnt<=0;
// end
// else begin
// out1<=0;
// out2<=0;
// // cnt<=cnt;
// end
// end
// end
//*************code***********//
endmodule
细节讲解
为什么第27~35行不能替换成第39~55行?
我也想换呀,但是换了之后就过不了测试点:
有没有佬懂的高速我为什么不能使用第39~55行?


