赞
踩
功能介绍:本次的代码是一个售卖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;
`
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。