admin 管理员组文章数量: 887007
用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
图:
本文标签: 用verilog实现卖报纸机
版权声明:本文标题:用verilog实现卖报纸机 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1732361280h1535287.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论