急!!!verilog自动售货机

作者&投稿:钦费 (若有异议请与网页底部的电邮联系)
求!自动售货机verilog编写!!~

我之前做过一个类似的,可以联系我

/*信号定义:
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
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

这个我自己写的。
module shoumaiji (clk,a,b,duanxuan,weixuan,out,out1);
input clk;
input a,b; //a为投入0.5元信号,b为投入1元信号
output [8:1]duanxuan;//输出8位段选信号
output weixuan;//输出1位位选信号
output out; //out为高电平时售卖机闸门打开,汽水掉出来
output out1; //out1为高电平时候找0.5元

reg weixuan;
reg [8:1]duanxuan;
reg [31:0]count; //数码管动态扫描计数
reg [31:0]count1; //用于计算售卖机闸门打开时间
reg [4:1]a1,b1; //用a1,b1寄存投入的0.5元和1元硬币数目
reg out,out1;

always @(posedge a or posedge out)
begin
if(out==1) a1<=0;//汽水出来后计数值清零
else a1<=a1+4'b1;
end

always @(posedge b or posedge out)
begin
if(out==1) b1<=0;//汽水出来后计数值清零
else b1<=b1+4'b1;
end

always@(posedge clk) //1KHz时钟
begin
if(a1==5) out<=1; //因为汽水为2.5,可以给5个0.5元
else if(a1==3&&b1==1) out<=1; //可以给3个0.5元和1个1元
else if(a1==1&&b1==2) out<=1; //,可以给1个0.5元和2个1元
else if(b1==3)begin out<=1;out1<=1;end //可以给3个一块的,系统找回0.5元
else if(a1==0&&b1==0) //如果没人投币,则两位数码管显示0
begin
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b00111111; //0
end

if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b00111111; //0
count<=0;
end
end
else if(a==1) //投币0.5元,显示0.5,假设数码管为共阴极的
begin
count<=count+1;
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b01101101; //5
end

if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b10111111; //0.
count<=0;
end
end

else if(b==1) //投币1元,显示01
begin
count<=count+1;
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0;
duanxuan<=8'b00000110; //1
end
if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1;
duanxuan<=8'b00111111; //0
count<=0;
end
end

if(out==1)
begin
if(count1==3000)//让闸门打开3秒,由于为1KHz时钟,故要数3000下
begin
out<=0;
out1<=0;
count1<=0;
end
else count1<=count1+1;
end

end
endmodule

  module sale_machine(
  clk ,
  rstn ,

  set_ok , //BTN
  set_cancel , //BTN
  set_up , //BTN
  set_down , //BTN
  set_commodity_sel , //DATA DISP
  set_commodity_price , //DATA DISP

  money_in_05 , //PULSE
  money_in_10 , //PULSE

  buy_in_ok , //BTN
  buy_in_cancel , //BTN

  buy_out_ok_flag , //LED
  buy_out_ng_flag , //LED

  commodity_out , //PULSE
  coin_out_en , //PULSE
  coin_out_num //PULSE
  );
  //-------------------------------------------
  //signal
  //-------------------------------------------
  input clk ;
  input rstn ;

  input set_ok ;
  input set_cancel ;
  input set_up ;
  input set_down ;
  output [1:0] set_commodity_sel ;
  output [15:0] set_commodity_price ;

  input money_in_05 ;
  input money_in_10 ;

  input [3:0] buy_in_ok ;
  input buy_in_cancel ;

  output [3:0] buy_out_ok_flag ;
  output buy_out_ng_flag ;

  output [3:0] commodity_out ;
  output coin_out_en ;
  output [31:0] coin_out_num ;

  //-------------------------
  //set mode signal
  //-------------------------
  //pulse check out
  wire n_set_ok_p ;
  wire n_set_cancel_p ;
  wire n_set_up_p ;
  wire n_set_down_p ;
  reg r_set_ok ;
  reg r_set_cancel ;
  reg r_set_up ;
  reg r_set_down ;
  //set state
  reg r_set_idle_st ;
  reg r_set_select_st ;
  reg r_set_price_st ;
  //set datain
  reg [1:0] r_sel ;
  reg [15:0] r_price ;
  reg [15:0] r_commodity_A_pr ;
  reg [15:0] r_commodity_B_pr ;
  reg [15:0] r_commodity_C_pr ;
  reg [15:0] r_commodity_D_pr ;

  //-------------------------
  //buy commodity signal
  //-------------------------
  //pulse check out
  wire [3:0] n_buy_in_ok_p ;
  wire n_buy_in_cancel_p ;
  reg [3:0] r_buy_in_ok ;
  reg r_buy_in_cancel ;

  //buy out flag
  wire n_buy_bought ;
  wire n_buy_in_ok_all ;
  wire n_buy_out_ok_all ;
  wire [3:0] buy_out_ok_flag ;

  wire buy_out_ng_flag_clr ;
  reg [3:0] r_buy_out_ng_flag_cnt;

  reg buy_out_ng_flag ;

  //money cnt
  reg clr ;
  reg [31:0] r_money_cnt ;

  //-------------------------
  //coin out signal
  //-------------------------
  reg coin_out_en ;
  reg [31:0] coin_out_num ;

  //-------------------------------------------
  //rtl
  //-------------------------------------------

  //-------------------------
  //set mode rtl
  //-------------------------
  //pulse check out
  assign n_set_ok_p = set_ok & ~r_set_ok ;
  assign n_set_cancel_p = set_cancel & ~r_set_cancel ;
  assign n_set_up_p = set_up & ~r_set_up ;
  assign n_set_down_p = set_down & ~r_set_down ;

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_set_ok <= 1'b0;
  r_set_cancel <= 1'b0;
  r_set_up <= 1'b0;
  r_set_down <= 1'b0;
  end
  else
  begin
  r_set_ok <= set_ok ;
  r_set_cancel <= set_cancel ;
  r_set_up <= set_up ;
  r_set_down <= set_down ;
  end
  end

  //set state
  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_set_idle_st <= 1'b1;
  end
  else begin
  if(n_set_ok_p) begin
  if(r_set_price_st) r_set_idle_st <= 1'b1;
  else if(r_set_idle_st) r_set_idle_st <= 1'b0;
  else r_set_idle_st <= r_set_idle_st;
  end
  else if(n_set_cancel_p) r_set_idle_st <= 1'b1;
  end
  end

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_set_select_st <= 1'b0;
  end
  else begin
  if(n_set_ok_p) begin
  if(r_set_idle_st) r_set_select_st <= 1'b1;
  else if(r_set_select_st) r_set_select_st <= 1'b0;
  else r_set_select_st <= r_set_select_st;
  end
  else if(n_set_cancel_p) r_set_select_st <= 1'b0;
  end
  end

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_set_price_st <= 1'b0;
  end
  else begin
  if(n_set_ok_p) begin
  if(r_set_select_st) r_set_price_st <= 1'b1;
  else if(r_set_price_st) r_set_price_st <= 1'b0;
  else r_set_price_st <= r_set_price_st;
  end
  else if(n_set_cancel_p) r_set_price_st <= 1'b0;
  end
  end

  //set datain
  assign set_commodity_sel = r_sel;
  assign set_commodity_price = r_price;

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_sel <= 2'b00;
  end
  else begin
  if(r_set_idle_st) r_sel <= 2'b00;
  else if(r_set_select_st) begin
  if(n_set_up_p) r_sel <= r_sel + 2'b01;
  else if(n_set_down_p) r_sel <= r_sel - 2'b01;
  else r_sel <= r_sel;
  end
  end
  end

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_price <= 16'h0000;
  end
  else begin
  if(r_set_idle_st) r_price <= 16'h0000;
  else if(r_set_select_st) begin
  if(n_set_up_p) begin
  if(r_sel == 2'b00) r_price <= r_commodity_B_pr;
  else if(r_sel == 2'b01) r_price <= r_commodity_C_pr;
  else if(r_sel == 2'b10) r_price <= r_commodity_D_pr;
  else if(r_sel == 2'b11) r_price <= r_commodity_A_pr;
  end
  else if(n_set_down_p) begin
  if(r_sel == 2'b00) r_price <= r_commodity_D_pr;
  else if(r_sel == 2'b01) r_price <= r_commodity_A_pr;
  else if(r_sel == 2'b10) r_price <= r_commodity_B_pr;
  else if(r_sel == 2'b11) r_price <= r_commodity_C_pr;
  end
  else
  r_price <= r_price;
  end
  else if(r_set_price_st) begin
  if(n_set_up_p) r_price <= r_price + 2'b01;
  else if(n_set_down_p) r_price <= r_price - 2'b01;
  else r_price <= r_price;
  end
  end
  end

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_commodity_A_pr <= 16'h0000;
  r_commodity_B_pr <= 16'h0000;
  r_commodity_C_pr <= 16'h0000;
  r_commodity_D_pr <= 16'h0000;
  end
  else begin
  if((r_set_price_st) && (n_set_ok_p)) begin
  if(r_sel == 2'b00) r_commodity_A_pr <= r_price;
  else if(r_sel == 2'b01) r_commodity_B_pr <= r_price;
  else if(r_sel == 2'b10) r_commodity_C_pr <= r_price;
  else if(r_sel == 2'b11) r_commodity_D_pr <= r_price;
  end
  else begin
  r_commodity_A_pr <= r_commodity_A_pr;
  r_commodity_B_pr <= r_commodity_B_pr;
  r_commodity_C_pr <= r_commodity_C_pr;
  r_commodity_D_pr <= r_commodity_D_pr;
  end
  end
  end

  //-------------------------
  //buy commodity rtl
  //-------------------------
  //pulse check out
  assign n_buy_in_ok_p[0] = buy_in_ok[0] & ~r_buy_in_ok[0] ;
  assign n_buy_in_ok_p[1] = buy_in_ok[0] & ~r_buy_in_ok[1] ;
  assign n_buy_in_ok_p[2] = buy_in_ok[0] & ~r_buy_in_ok[2] ;
  assign n_buy_in_ok_p[3] = buy_in_ok[0] & ~r_buy_in_ok[3] ;
  assign n_buy_in_cancel_p = buy_in_cancel & ~r_buy_in_cancel ;

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_buy_in_ok <= 4'b0000;
  r_buy_in_cancel <= 1'b0;
  end
  else if(r_set_idle_st) //in idle
  begin
  r_buy_in_ok <= buy_in_ok ;
  r_buy_in_cancel <= buy_in_cancel;
  end
  else begin
  r_buy_in_ok <= 4'b0000;
  r_buy_in_cancel <= 1'b0;
  end
  end

  //buy out flag
  assign commodity_out[0] = (n_buy_in_ok_p[0]) && (buy_out_ok_flag[0]);
  assign commodity_out[1] = (n_buy_in_ok_p[1]) && (buy_out_ok_flag[1]);
  assign commodity_out[2] = (n_buy_in_ok_p[2]) && (buy_out_ok_flag[2]);
  assign commodity_out[3] = (n_buy_in_ok_p[3]) && (buy_out_ok_flag[3]);

  assign n_buy_bought = ( ((n_buy_in_ok_p[0]) && (buy_out_ok_flag[0])) ||
  ((n_buy_in_ok_p[1]) && (buy_out_ok_flag[1])) ||
  ((n_buy_in_ok_p[2]) && (buy_out_ok_flag[2])) ||
  ((n_buy_in_ok_p[3]) && (buy_out_ok_flag[3])) );

  assign n_buy_in_ok_all = | n_buy_in_ok_p; //BTN IN ALL
  assign n_buy_out_ok_all = | buy_out_ok_flag; //LED OUT ALL
  assign buy_out_ok_flag[0] = (r_money_cnt >= r_commodity_A_pr) ? 1'b1 : 1'b0;
  assign buy_out_ok_flag[1] = (r_money_cnt >= r_commodity_B_pr) ? 1'b1 : 1'b0;
  assign buy_out_ok_flag[2] = (r_money_cnt >= r_commodity_C_pr) ? 1'b1 : 1'b0;
  assign buy_out_ok_flag[3] = (r_money_cnt >= r_commodity_D_pr) ? 1'b1 : 1'b0;

  assign buy_out_ng_flag_clr = (r_buy_out_ng_flag_cnt == 4'hF) ? 1'b1 : 1'b0;

  always @(posedge clk or negedge rstn) begin
  if(!rstn) r_buy_out_ng_flag_cnt <= 4'h0;
  else if(buy_out_ng_flag_clr)
  r_buy_out_ng_flag_cnt <= 4'h0;
  else if(buy_out_ng_flag)
  r_buy_out_ng_flag_cnt <= r_buy_out_ng_flag_cnt + 4'h1;
  else
  r_buy_out_ng_flag_cnt <= 4'h0;
  end

  always @(posedge clk or negedge rstn) begin
  if(!rstn) buy_out_ng_flag <= 1'b0;
  else if((~n_buy_out_ok_all) && (n_buy_in_ok_all))
  buy_out_ng_flag <= 1'b1;
  else if(buy_out_ng_flag_clr)
  buy_out_ng_flag <= 1'b0;
  end

  //money cnt
  always @(posedge clk or negedge rstn) begin
  if(!rstn) clr <= 1'b0;
  else if(n_buy_bought || buy_in_cancel)
  clr <= 1'b1;
  else
  clr <= 1'b0;
  end

  always @(posedge clk or negedge rstn) begin
  if(!rstn) begin
  r_money_cnt <= 32'h00000000;
  end
  else begin
  if(money_in_05) r_money_cnt <= r_money_cnt + 32'h00000001;
  else if(money_in_10) r_money_cnt <= r_money_cnt + 32'h00000002;
  else if((n_buy_in_ok_p[0]) && (buy_out_ok_flag[0]))
  r_money_cnt <= r_money_cnt - r_commodity_A_pr;
  else if((n_buy_in_ok_p[1]) && (buy_out_ok_flag[1]))
  r_money_cnt <= r_money_cnt - r_commodity_B_pr;
  else if((n_buy_in_ok_p[2]) && (buy_out_ok_flag[2]))
  r_money_cnt <= r_money_cnt - r_commodity_C_pr;
  else if((n_buy_in_ok_p[3]) && (buy_out_ok_flag[3]))
  r_money_cnt <= r_money_cnt - r_commodity_D_pr;
  else if(clr)
  r_money_cnt <= 32'h00000000;
  end
  end

  //-------------------------
  //coin out rtl
  //-------------------------
  always @(posedge clk or negedge rstn) begin
  if(!rstn) coin_out_en <= 1'b0;
  else if(clr)
  coin_out_en <= 1'b1;
  else
  coin_out_en <= 1'b0;
  end

  always @(posedge clk or negedge rstn) begin
  if(!rstn) coin_out_num <= 32'h00000000;
  else if(clr)
  coin_out_num <= r_money_cnt;
  else
  coin_out_num <= 32'h00000000;
  end

  endmodule

http://x.soso.com/cgi-bin/show_detail?Hash=5837AE21070DE484A6B69A7FB16D2289DA8CF28E

这是QQ资源下载,进去直接下载就好了,这个没有你说的这么繁琐,
但是足够你参考的了,希望可以帮到你。


Verilo HDL数字设计教程图书信息
这是一本由西安电子科技大学出版社出版的Verilo HDL数字设计教程,它于2010年4月1日首次发行,作为第一版呈现。这本书共包含240页,以简体中文为主要语言编写,适合读者阅读。它的开本设计为16开,方便携带和阅读。书籍的国际标准书号为9787560624143,同时书背还标注了相同的条形码,便于识别和购买。整体尺...

Verilo HDL数字设计教程目录
第1章 1.1 电子系统设计技术的发展 1.2 数字系统典型设计流程 1.3 HDL概述 1.3.1 HDL的定义 1.3.2 Verilog HDL的特点 1.3.3 Verilog HDL的功能 1.4 QuartusⅡ简介 1.5 硬件描述语言发展趋势 1.6 小结 习题1第2章 2.1 编写简单Verilog HDL程序 2.1.1 程序...

...然后写出调用此半加器而构成一位全加器的verilo
搜一下:写出一个半加器的verilog代码,然后写出调用此半加器而构成一位全加器的verilo

verilog语言不能打开dump.vcd怎么解决?
vcd是仿真的波形文件,verilo是用来设计逻辑和testbench用的,你不要用verilog打开,你用仿真器中看波形的工具打开vcd文件就可以看波形了。

北工大 数字逻辑基础与verilo硬件描述语言课后答案 清华大学出版社 201...
《数字逻辑基础与Verilog硬件描述语言》——贾熹滨等清华大学出版社2012.08.习题解答1-4章第1章1.1写出下列各数的按权展开式数制和码制(1024.5)10=1×103+0×102+2×101+4×100+5×10-1(10110)2=1×24+0×23+1×22+1×21+0×20(237)8=2×82+3×81+7×80(A01D)16=A×163...

verilog语言中,这句话是什么意思?
其实这是一个判断式,假设a == (nn_mode == 2'b00),所以这个意思就是如果nn_mode == 2'b00说明括号内式子成立,a == 1;否则 a == 0.是1bit的。emif_oen_o 是1 bit的,而nn_mode 2 bit的他俩之间没什么关系。

巴里坤哈萨克自治县17164092004: 急!!!verilog自动售货机 -
函虾鼻咽: module sale_machine(clk ,rstn ,set_ok , //BTNset_cancel , //BTNset_up , //BTNset_down , //BTNset_commodity_sel , //DATA DISPset_commodity_price , //DATA DISPmoney_in_05 , //PULSEmoney_in_10 , //PULSEbuy_in_ok , //BTN...

巴里坤哈萨克自治县17164092004: 用VHDL语言或Verilog语言编写简单自动售货机 -
函虾鼻咽: 用verilog HDL 改成VHDL 就可以了 用状态机写的/*信号定义: clk: 时钟输入; reset: 为系统复位信号; half_dollar: 代表投入5角硬币; one_dollar: 代表投入1元硬币; half_out: 表示找零信号; dispense: 表示机器售出一瓶饮料; collect...

巴里坤哈萨克自治县17164092004: 求助!数字电路verilog HDL 自动售货机的程序
函虾鼻咽: /*信号定义: clk: 时钟输入; reset: 为系统复位信号; half_dollar: 代表投入5角硬币; one_dollar: 代表投入1元硬币; half_out: 表示找零信号; dispense: 表示机器售出一瓶饮料; collect: 该信号用于提示投币者取走饮料. */ module ...

巴里坤哈萨克自治县17164092004: 求助!数字电路verilog HDL 自动售货机的程序 -
函虾鼻咽: 很多fpga学习的书上都有例程,你可以查查看.你也可以在百度文库中搜“自动售货机”,有论文和具体程序.

巴里坤哈萨克自治县17164092004: 用xilinx编程,verilog设计自动售货机autoseller,在调用display模块出现了下面这个错误 -
函虾鼻咽: 指的是你的display模块中的信号"autoseller7"连接了很多端口.建议你检查这个信号的连接.祝你成功.

巴里坤哈萨克自治县17164092004: 自动售货机plc设计 -
函虾鼻咽: 只会用三菱的.输入X000 X001 X002 表示三种钱,X003 X004表示两种饮料的按钮.输出Y000 Y001 Y002 Y003 表示两个灯和两种饮料.设置一个寄存器D0表示钱的累加.用加法发指令直接加就行(如ADD K5 D0即寄存器里面多了五块钱)...

巴里坤哈萨克自治县17164092004: verilog的课程设计
函虾鼻咽: module shoumaiji (clk,a,b,duanxuan,weixuan,out,out1); input clk; input a,b; //a为投入0.5元信号,b为投入1元信号,假设有硬币投入时产生一个高脉冲 output [8:1]duanxuan;//输出8位段选信号 output weixuan;//输出1位位选信号 output out; //out为...

巴里坤哈萨克自治县17164092004: 用VHDL设计自动售货机,急求!!
函虾鼻咽: 你好.很幸运看到你的问题.但是又很遗憾到现在还没有人回答你的问题.也可能你现在已经在别的地方找到了答案,那就得恭喜你啦.对于你的问题我爱莫能助!可能是你问的问题有些专业了.或者别人没有遇到或者接触过你的问题,所以帮不了你.建议你去问题的相关论坛去求助,那里的人通常比较多,也比较热心,可能能快点帮你解决问题.希望我的回答也能够帮到你!快过年了,最后祝您全家幸福健康快乐每一天!

巴里坤哈萨克自治县17164092004: VHDL语言编写自动售货机 -
函虾鼻咽: 自动售货机vhdl程序 (1)自动售货机vhdl程序如下: --文件名:pl_auto1.vhd.--功能:货物信息存储,进程控制,硬币处理,余额计算,显示等功能.--说明:显示的钱数coin的以5角为单位.library ieee; use ieee.std_logic_arith.all; use ieee.std...

巴里坤哈萨克自治县17164092004: 寻自动售货机的工作原理和工作图 -
函虾鼻咽: 自动售货机的核心是单片机,没有使用PLC的! 我见过的单片机有: 1、摩托罗拉 MC68HC908GP32CP 2、飞 利 浦 P87C52EFAA 自动售货机有自己专用的通讯协议,欧美系列为“MDB”,日韩系列为“VCCS”,不是什么232、485、CAN...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网