当前位置:   article > 正文

用Verilog 实现自动售货机_自动售饮料机,饮料2.5元,可以投0.5和1元,设找零功能,设计一个状态

自动售饮料机,饮料2.5元,可以投0.5和1元,设找零功能,设计一个状态

功能介绍:本次的代码是一个售卖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;
`

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/641305
推荐阅读
相关标签
  

闽ICP备14008679号