题解 | #游戏机计费程序#(简单版本)
游戏机计费程序
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 ); //=========================================================================\\ //*****************************define sinals*******************************\\ //=========================================================================\\ //=========================================================================\\ //*****************************main code***********************************\\ //=========================================================================\\ always@(posedge clk or negedge rst_n)begin if(!rst_n) remain <= 'd0 ; else if(set) remain <= remain + money ; else if(remain == 'd0) remain <= 'd0 ; else if(boost == 1'b1) remain <= remain - 'd2 ; else if(boost == 1'b0) remain <= remain - 'd1 ; else remain <= remain ; end always@(posedge clk or negedge rst_n)begin if(!rst_n)begin yellow <= 1'b0 ; red <= 1'b0 ; end else if(remain > 'd0 && remain < 'd10)begin yellow <= 1'b1 ; red <= 1'b0 ; end else if(remain == 'd0)begin yellow <= 1'b0 ; red <= 1'b1 ; end else begin yellow <= 1'b0 ; red <= 1'b0 ; end end endmodule