欢迎来到天天文库
浏览记录
ID:1107219
大小:42.50 KB
页数:5页
时间:2017-11-07
《多功能自动售货机》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、moduleauto_seller(clk,rst,display,btn_ok,btn_mon,btn_sell,led_warn,led,Dir,StepDrive);inputclk,rst,btn_ok;input[2:0]btn_mon;//选择放入的钱input[3:0]btn_sell;//选择商品bbt_5,gz_10,kqs_15,kl_20output[6:0]led;//led_5,led_10,led_15,led_20outputled_warn;//钱不足,指示灯output[15:0]display;//数
2、码管显示投入面值,diaplay[15:8]位选,display[7:0]段码inputDir;regStepEnable;output[3:0]StepDrive;reg[3:0]StepDrive;reg[2:0]state;reg[31:0]StepCounter=32'b0;parameterStepLockOut=32'd200000;//250HZregInternalStepEnable;regclk1;reg[6:0]led;regled_warn;//警告放入钱不足reg[15:0]display;reg[31:0]c
3、ounter;(*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;parameterCOUNT1=25'd10000;/*分频使数码管显示稳定*/always@(posedgeclk)beginif(counter==0)begincounter<=COUNT1;clk1<=~clk1;endelsecounter<=counter-1;endalways@(neged
4、gerstorposedgeclk)beginif(!rst)beginled=7'b111_1111;//LED灭price_all=0;//价格清零led_warn=1;price=0;endelsebegin/*三种面值共8种组合*/case(btn_mon)3'b001:beginprice_all=5;end3'b010:beginprice_all=10;end3'b100:beginprice_all=50;end3'b011:beginprice_all=15;end3'b101:beginprice_all=55;en
5、d3'b110:beginprice_all=60;end3'b111:beginprice_all=65;enddefault:beginprice_all=0;endendcasecase(btn_sell)4'b0001:beginprice=5;end4'b0010:beginprice=10;end4'b0100:beginprice=15;end4'b1000:beginprice=20;enddefault:beginprice=0;endendcaseif(btn_ok==0)beginif(price_all6、e)//放入钱不足beginled_warn=0;price=0;endelsebegin//金钱足够price_all=price_all-price;if(price_all==0)led_warn=1;case(price)//LED灯显示货物卖出5:beginled=7'b111_1110;end10:beginled=7'b111_1101;end15:beginled=7'b111_1011;end20:beginled=7'b111_0111;enddefault:beginled=7'b111_1111;endendca7、seendendendend/*******************************电机驱动*********************************/always@(posedgeclkornegedgerst)beginif(!rst)beginStepDrive<=4'b0;state<=3'b0;StepCounter<=32'b0;endelsebeginif(btn_ok==0)beginif(~led8、7'b000_0000)StepEnable=1'b1;elseStepEnable=1'b0;endif9、(StepEnable==1'b1)beginInternalStepEnable<=1'b1;StepEnable=1'b0;endStepCounter<=StepCounter+31'b1;if(St
6、e)//放入钱不足beginled_warn=0;price=0;endelsebegin//金钱足够price_all=price_all-price;if(price_all==0)led_warn=1;case(price)//LED灯显示货物卖出5:beginled=7'b111_1110;end10:beginled=7'b111_1101;end15:beginled=7'b111_1011;end20:beginled=7'b111_0111;enddefault:beginled=7'b111_1111;endendca
7、seendendendend/*******************************电机驱动*********************************/always@(posedgeclkornegedgerst)beginif(!rst)beginStepDrive<=4'b0;state<=3'b0;StepCounter<=32'b0;endelsebeginif(btn_ok==0)beginif(~led
8、7'b000_0000)StepEnable=1'b1;elseStepEnable=1'b0;endif
9、(StepEnable==1'b1)beginInternalStepEnable<=1'b1;StepEnable=1'b0;endStepCounter<=StepCounter+31'b1;if(St
此文档下载收益归作者所有