用verilog实现卖报纸机

题目:画状态机,接收1,2,5分钱的卖报纸机,每份报纸5分钱。
在这里插入图片描述程序代码:

module maibaoji(
input clk,
input rst,
input [2:0]din,
output reg [1:0]dout
);

parameter idle = 0,
st1 = 1,
st2 = 2,
st3 = 3,
st4 = 4,
st5 = 5,
st6 = 6;
reg [2:0]current_state,next_state;

always@(posedge clk or negedge rst)begin
if(!rst)
current_state <= idle;
else
current_state <= next_state;
end

always@(next_state or current_state or din or dout)begin
case(current_state)
idle:
if(din == 3’b100)
next_state = st1;
else if(din == 3’b010)
next_state = st2;
else if(din == 3’b001)
next_state = st5;
else if(din == 3’b000)
next_state = idle;
st1:
if(din == 3’b100)
next_state = st2;
else if(din == 3’b010)
next_state = st3;
else if(din == 3’b000)
next_state = st1;
st2:
if(din == 3’b100)
next_state = st3;
else if(din == 3’b010)
next_state = st4;
else if(din == 3’b000)
next_state = st2;
st3:
if(din == 3’b100)
next_state = st4;
else if(din == 3’b010)
next_state = st5;
else if(din == 3’b000)
next_state = st3;
st4:
if(din == 3’b100)
next_state = st5;
else if(din == 3’b010)
next_state = st6;
else if(din == 3’b000)
next_state = st4;
st5:
if(din == 3’b100)
next_state = st1;
else if(din == 3’b010)
next_state = st2;
else if(din == 3’b000)
next_state = idle;
st6:
if(din == 3’b100)
next_state = st2;
else if(din == 3’b010)
next_state = st3;
else if(din == 3’b000)
next_state = st1;
default:
next_state = idle;
endcase
end
always@(posedge clk)begin
if(next_state == 5)
dout <= 2’b10;
else if (next_state == st6)
dout <= 2’b11;
else
dout <= 2’b00;
end
endmodule

图:
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值