用Verilog 实现自动售货机

功能介绍:本次的代码是一个售卖2.5元的饮料机,投币只能投0.5元和1元的硬币,投币达到2.5元时自动出饮料,投币3元时,会出饮料和找零0.5元。部分代码如下:`
always @(posedge clk or negedge rst_n) begin
if (!rst_n) curr_state <=S0;
else curr_state <=#1 next_state;
end
always @(one,half,curr_state) begin
case(curr_state)

S0:begin
if (half) next_state = S1;
else if (one) next_state = S2;
else next_state = S0;

end

S1:begin
if (half) next_state = S2;
else if (one) next_state = S3;
else next_state = S1;

end

S2:begin
if (half) next_state = S3;
else if (one) next_state = S4;
else next_state = S2;

end

S3:begin
if (half) next_state = S4;
else if (one) next_state = S5;
else next_state = S3;

end

S4:begin
if (half) next_state = S5;
else if (one) next_state =S6;
else next_state = S4;

end

S5:begin
next_state = S0;

end

S6:begin
next_state = S0;

end

default next_state = S0;

endcase

end
assign out = ((curr_state == S5)|| (curr_state == S6)) ?1:0;
assign cout = (curr_state ==S6) ? 1:0;
`

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值