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

游戏机计费程序

http://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 <= 0;
        end
        else if(set)begin
            remain <= remain + money;
        end
        else if(boost)begin
            remain <= remain - 2;
        end
        else 
            remain <= remain - 1;
    end
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n)begin
            yellow <= 0;
            red <= 0;
        end
        else if(remain < 10 && remain > 0)begin
            yellow <= 1;
            red <= 0;
        end
        else if(remain == 0)begin
            yellow <= 0;
            red <= 1; 
        end
        else begin 
            yellow <= 0;
            red <= 0;
        end
    end
    
endmodule
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-15 12:20
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-11 13:34
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-16 18:05
何尝不是一种学历歧视呢
码农索隆:楼主明确拒绝,并说明拒绝原因了,这hr倒是挺忠心护主的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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