⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sel_stamp.v

📁 可实现找钱功能的自动售邮票机
💻 V
字号:
module sel_stamp(m10,m5,confirm,cancel,charge,owe_led,out_led,rst,out_coin,out_stamp,incoin1,                 incoin10,incoin5,incount,count,clk);input m10,m5,confirm,cancel,charge,incoin1,incoin5,incoin10,rst,clk;output reg[1:0] out_stamp;output reg[2:0] out_coin;output reg[5:0] incount,count;output reg owe_led,out_led;        reg[2:0] state,nstate;parameter idle=3'b0,          start=3'b001,          A=3'b010,          B=3'b011,          C=3'b100;always@(posedge clk)if(rst)state<=idle;elsestate<=nstate;  always@(posedge m10,posedge m5,posedge confirm,posedge cancel,posedge charge,posedge incoin1,posedge incoin5,posedge incoin10,rst)                            case(state)                        idle: begin               nstate=start;               incount=0;               owe_led=0;               out_led=0;               count=0;               out_stamp=0;               out_coin=0;                          end                        start:begin                  out_coin=0;                  owe_led=1'b0;                  out_led=1'b0;              if(m10)                      begin                          nstate=A;                          count='d10;                      end                       else if(m5)                     begin                         count='d5;                         nstate=A;                     end else                     nstate=start;                                      end                  A:  if(incoin1==1)                      begin                       incount=incount+1;                       if(incount<count)                       begin                       nstate=A;                       owe_led=1'b1;                   end                       else                       begin                       nstate=B;                       owe_led=1'b0;                   end                   end                       else if(incoin5==1)                       begin                       incount=incount+5;                       if(incount<count)                       begin                       nstate=A;                       owe_led=1'b1;                   end                       else                       begin                       nstate=B;                       owe_led=1'b0;                   end                   end                       else if(incoin10==1)                       begin                       incount=incount+10;                       if(incount<count)                       begin                       nstate=A;                       owe_led=1'b1;                   end                    else                    begin                    nstate=B;                    owe_led=1'b0;                     out_led=1'b1;                end            end                   else if(cancel==1)                        nstate=C;                    B: begin                       out_led=0;                   if(confirm)                       begin                           if(count==4'b0101)                           begin                               incount=incount-5'b0101;                               out_stamp=2'b01;                           end                           else if(count==10)                            begin                                incount=incount-5'b1010;                                out_stamp=2'b10;                            end                            nstate=C;                             end                        else                         nstate=C;                    end                                               C:begin                       out_stamp=2'b0;                       out_led=0;                    if (charge)                      begin                          if(incount<5)                          begin                              out_coin=3'b001;                              incount=incount-1;                              if(!incount)                                 nstate=start;                             else                                nstate=C;                          end                          else if(incount<10)                          begin                              out_coin=3'b010;                              incount=incount-'d5;                              if(!incount)                                 nstate=start;                             else                                nstate=C;                          end                          else if(incount<=20)                          begin                              out_coin=3'b100;                              incount=incount-'d10;                              if(!incount)                                 nstate=start;                             else                                nstate=C;                          end                           else                          nstate=start;                      end                       else                       begin                      nstate=start;                      incount=0;                  end              end                      default:nstate=start;              endcase      endmodule                                                                 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -