求助!数字电路verilog HDL 自动售货机的程序

编写Verilog设计一个自动售饮料机,每瓶饮料5角,只能投入1元或者 5角硬币,一次只能购买一瓶饮料。信号定义如下 clk: 时钟输入; reset: 系统复位信号; half_yuan: 代表投入5角硬币; one_yuan: 代表投入1元硬币; half_out: 表示找零信号; dispense: 表示机器售出一瓶饮料; collect: 该信号用于提示投币者取走饮料。 谢谢啦 !!有爱的帮下忙哈
2026年09月19日 22:02
有2个网友回答
网友(1):

/*信号定义:
clk: 时钟输入;
reset: 为系统复位信号;
half_dollar: 代表投入5角硬币;
one_dollar: 代表投入1元硬币;
half_out: 表示找零信号;
dispense: 表示机器售出一瓶饮料;
collect: 该信号用于提示投币者取走饮料。 */
module sell(one_dollar,half_dollar,
collect,half_out,dispense,reset,clk);
parameter idle=0,one=2,half=1,two=3,three=4;
//idle,one,half,two,three 为中间状态变量,代表投入币值的几种情况

input one_dollar,half_dollar,reset,clk;
output collect,half_out,dispense;
reg collect,half_out,dispense;
reg[2:0] D;
always @(posedge clk)

begin
if(reset)
begin

dispense=0; collect=0;
half_out=0; D=idle;

end
case(D)

idle:
if(half_dollar) D=half;
else if(one_dollar)

D=one;

half:
if(half_dollar) D=one;
else if(one_dollar)

D=two;

one:
if(half_dollar) D=two;
else if(one_dollar)
D=three;

two:
if(half_dollar) D=three;
else if(one_dollar)
begin

dispense=1; //售出饮料
collect=1; D=idle;

end

three:
if(half_dollar)
begin

dispense=1; //售出饮料
collect=1; D=idle;

end
else if(one_dollar)
begin

dispense=1; //售出饮料
collect=1;
half_out=1; D=idle;

end
endcase
end
endmodule

网友(2):

http://zhidao.baidu.com/question/158766262.html