题解 | #游戏机计费程序#

游戏机计费程序

https://www.nowcoder.com/practice/50188fb7e23b4eee86f8c463c8284f5e

`timescale 1ns/1ns

module game_count
    (
		input rst_n, //异位复位信号,低电平有效
        input clk, 	//时钟信号
        input [9:0]money,
        input set,
		input boost,
		output reg[9:0]remain,
		output reg yellow,
		output reg red
    );
    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            remain <= 'd0;
        end
        else begin
            case({set,boost})
                2'b11,
                2'b10: remain <= remain + money;
                2'b00: remain <= (remain=='d0)?'d0:(remain-'d1);
                2'b01: remain <= (remain>='d2)?(remain-'d2):remain;
                default: remain <= remain;
            endcase
        end
    end

    always@(posedge clk or negedge rst_n) begin
        if(!rst_n) begin
            yellow <= 1'b0;
            red <= 1'b0;
        end
        else begin
            yellow <= (remain<'d10) & (remain>'d0);
            red <= (remain=='d0);
        end
    end
endmodule

全部评论

相关推荐

白火同学:1、简历可以浓缩成一页,简历简历先要“简”方便HR快速过滤出有效信息,再要“历”用有效信息突出个人的含金量。 2、教育背景少了入学时间~毕业时间,HR判断不出你是否为应届生。 3、如果你的平台账号效果还不错,可以把账号超链接或者用户名贴到对应位置,一是方便HR知道你是具体做了什么内容的运营,看到账号一目了然,二是口说无凭,账号为证,这更有说服力。
面试被问期望薪资时该如何...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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