clk:时钟信号;
reset:系统复位清零;
half:5角硬币模拟信号;
one:1元硬币模拟信号;
mout:有找零钱输出显示;
tout:有邮票输出信号;
charge:取零钱;
ok:取邮票;
mh:投入金额数码显示的高4位;
ml: 投入金额数码显示的低4位。
*/
module ticket(one,half,mh,ml,tout,mout,reset,clk,ok,charge);
parameter a="0",b=1,c=2,d=3,e=4; //定义5个状态
input one,half,reset,clk,ok,charge;
output tout,mout,mh,ml;
reg mout,tout;
reg[3:0] money;
reg[3:0] mh;
reg[3:0] ml;
always@(posedge clk)
begin
tout=1;
end
if(reset)
begin
tout=0;
mout=0;
money=a;
{mh,ml}=8'b00000000;
end
case(money)
a:
if(half) begin money="b";{mh,ml}=8'b00000101;end
else if(one)
begin money="c";{mh,ml}=8'b00010000;end
b:
if(half) begin money="c";{mh,ml}=8'b00010000;end
else if(one)
begin money="d";{mh,ml}=8'b00010101;end
c:
if(half) begin money="d";{mh,ml}=8'b00010101;end
else if(one)
begin money="e";{mh,ml}=8'b00100000;end
d:
if(half) begin money="e";{mh,ml}=8'b00100000;end
else if(one)
begin money="a";
{mh,ml}=8'b00100101;
mout=0;
tout=1; //sell
end
e:
if(half)
begin
money=a;
{mh,ml}=8'b00100101;
tout=1; //sell
end
else if(one)
begin
money=a;
{mh,ml}=8'b00110000;
endcase
if({mh,ml}==8'b00100101) begin
if(ok) begin tout="0";mout=0;{mh,ml}=8'b00000000;end
if({mh,ml}==8'b00110000) begin
end
endmodule
文章评论(0条评论)
登录后参与讨论