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

📄 auto_sell_drink.txt

📁 这是用verilogHDL语言编写的自动出售饮料的电路。会根据顾客投入硬币的多少来送出饮料
💻 TXT
字号:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    10:45:08 03/01/2009 
// Design Name: 
// Module Name:    AUTO_SELL_DRINK 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////

/**

/*信号定义:
clk: 时钟输入;
reset: 为系统复位信号;
half_dollar: 代表投入5 角硬币;
one_dollar: 代表投入1 元硬币;
half_out: 表示找零信号;
dispense: 表示机器售出一瓶饮料;
collect: 该信号用于提示投币者取走饮料。 */

module sell(one_dollar,half_dollar,collect,half_out,dispense,reset,clk);

parameter idle=0,one=2,half=1,two=3,three=4;

//idle,one,half,two,three 为中间状态变量,代表投入币值的几种情况

input one_dollar,half_dollar,reset,clk;

output collect,half_out,dispense;

reg collect,half_out,dispense;

reg[2:0] D;
//////////////////////////////////////////////////////////
always @(posedge clk)
begin
     if(reset)
        begin
           dispense=0; 
           collect=0;
           half_out=0; 
           D=idle;
        end
    else
   case(D)
idle:
     if(half_dollar)
       D=half;
     else if(one_dollar)
      D=one;
half:
     if(half_dollar)
       D=one;
      else if(one_dollar)
     D=two;
one:
     if(half_dollar) 
      D=two;
     else if(one_dollar)
       D=three;
two:
      if(half_dollar) 
       D=three;
      else if(one_dollar)
        begin
           dispense=1; //售出饮料
           collect=1;
           D=idle;
        end
three:
      if(half_dollar)
        begin
          dispense=1; //售出饮料
          collect=1; 
          D=idle;
       end
      else if(one_dollar)
         begin
              dispense=1; //售出饮料
              collect=1;
              half_out=1;
             D=idle;
        end
endcase
end
endmodule

⌨️ 快捷键说明

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