题解 | #自动贩售机1#
自动贩售机1
https://www.nowcoder.com/practice/dcf59e6c51f6489093495acb1bc34dd8
//以0.5元硬币为单位,问题变成放入几个0.5元硬币,输出几个0.5元硬币
`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
);
reg [2 :0] cnt;
always @(posedge clk or negedge rst)
begin
if(!rst) begin
cnt <= 3'd0 ;
out1 <= 1'b0 ;
out2 <= 2'd0 ;
end
else begin
if(cnt >= 3) begin
out1 <= 1'b1 ;
out2 <= cnt - 3'd3 ;
cnt <= 3'd0 ;
end
else begin
out1 <= 1'b0 ;
out2 <= 2'd0 ;
cnt <= cnt + {d3,d2,d1} ;
end
end
end
endmodule
腾讯云智研发成长空间 5079人发布
查看6道真题和解析