EDA课程设计报告(自动售货机)(3)

2018-12-27 16:19

附录

(1)自动售货机主模块

module auto_seller(clk,rst,display,btn_ok,btn_mon,btn_sell, led_warn,led,StepDrive); input clk,rst,btn_ok;

input [2:0] btn_mon;//选择放入的钱

input [3:0] btn_sell;//选择商品bbt_5,gz_10,kqs_15,kl_20 output [6:0] led;//led_5,led_10,led_15,led_20 output led_warn;//钱不足,指示灯

output [15:0] display;//数码管显示投入面值,diaplay[15:8]=com位选,display[7:0]=段码

output[3:0] StepDrive; reg clk_500Hz; reg [6:0] led; wire s;

reg led_warn;//警告放入钱不足 reg [15:0] display; reg [31:0] counter;

(* synthesis,keep *)reg [9:0] price,price_all; reg [1:0] flag = 2'b00;//数码管显示标志位 reg [1:0] flag1 = 2'b00; reg [1:0] flag2 = 2'b00; parameter COUNT1 = 25'd10000;

step_motor u(.StepDrive(StepDrive), .clk(clk), . StepEnable(s), .rst(rst));//步进电机例化

assign s=(led[3:0]==4'b1111)||(btn_ok==1)||(led_warn==0); /*分频使数码管显示稳定*/ always @ (posedge clk)

begin

if(counter== 0)

begin

counter <= COUNT1; clk_500Hz <= ~clk_500Hz; end

else

counter <= counter-1;

end

always @(negedge rst or posedge clk)

begin if(!rst)

begin end

led = 7'b111_1111;//LED灭 price_all = 0;//价格清零 led_warn =1; price = 0;

else

begin/*三种面值共8种组合*/

case(btn_mon)

3'b001: begin price_all = 5;end 3'b010: begin price_all = 10;end 3'b100: begin price_all = 50;end 3'b011: begin price_all = 15;end 3'b101: begin price_all = 55;end 3'b110: begin price_all = 60;end 3'b111: begin price_all = 65;end default: begin price_all = 0;end

endcase

case(btn_sell)

4'b0001: begin price = 5;end 4'b0010: begin price = 10;end 4'b0100: begin price = 15;end 4'b1000: begin price = 20;end default: begin price = 0;end

endcase

if(btn_ok==0 )

begin

if(price_all < price) //放入钱不足

begin

led_warn = 0; price = 0;

end

else

begin //金钱足够

price_all = price_all-price; if(price_all ==0)led_warn = 1; case(price) //LED灯显示货物卖出

5: begin led = 7'b111_1110;end 10: begin led = 7'b111_1101;end 15: begin led = 7'b111_1011;end 20: begin led = 7'b111_0111;end default: begin led = 7'b111_1111;end

endcase

end

end end

end

/*分频后将时钟给数码管,数码管分别显示放入钱的多少、商品价格*/

always @(posedge clk_500Hz) begin

if(btn_sell)

begin

case(flag)

2'b00:

begin display<= {8'b1111_1110,1'b1,led7(price)}; flag=2'b01;end 2'b01:

begin display<= {8'b1111_1101,1'b0,led7(price/10)}; flag=2'b00;end

endcase if(btn_mon)

case(flag1)

2'b00: begin

display<= {8'b1111_1110,1'b1,led7(price_all)};

flag1=2'b01;end

2'b01: begin

display<= {8'b1111_1101,1'b0,led7(price_all/10)};

flag1=2'b00;end

endcase

end

else

begin

case(flag2) 2'b00:

begin display<={8'b1111_1110,1'b1,7'b0};flag2=2'b01;end 2'b01:

begin display<={8'b1111_1101,1'b1,7'b0};flag2=2'b00;end endcase end end

/*数码管段码表,供阳数码管[6:0]=hgfedcba*/ function [6:0] led7; input [3:0] dis_input;

begin

case (dis_input)

0 : led7 = 7'b100_0000; 1 : led7 = 7'b111_1001; 2 : led7 = 7'b010_0100; 3 : led7 = 7'b011_0000; 4 : led7 = 7'b001_1001; 5 : led7 = 7'b001_0010; 6 : led7 = 7'b000_0010; 7 : led7 = 7'b111_1000; 8 : led7 = 7'b000_0000; 9 : led7 = 7'b001_1000;

default : led7 = 7'b000_0000;

end

endcase

endfunction endmodule

(2)步进电机送货模块

module step_motor (StepDrive, clk, StepEnable, rst); input clk; input StepEnable;


EDA课程设计报告(自动售货机)(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2014年10月江苏省计算机等级考试全真试题4

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: