题解 | #自动贩售机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

全部评论

相关推荐

07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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