自动售货机设计和实现.docx

上传人:b****1 文档编号:1632050 上传时间:2023-05-01 格式:DOCX 页数:23 大小:417.54KB
下载 相关 举报
自动售货机设计和实现.docx_第1页
第1页 / 共23页
自动售货机设计和实现.docx_第2页
第2页 / 共23页
自动售货机设计和实现.docx_第3页
第3页 / 共23页
自动售货机设计和实现.docx_第4页
第4页 / 共23页
自动售货机设计和实现.docx_第5页
第5页 / 共23页
自动售货机设计和实现.docx_第6页
第6页 / 共23页
自动售货机设计和实现.docx_第7页
第7页 / 共23页
自动售货机设计和实现.docx_第8页
第8页 / 共23页
自动售货机设计和实现.docx_第9页
第9页 / 共23页
自动售货机设计和实现.docx_第10页
第10页 / 共23页
自动售货机设计和实现.docx_第11页
第11页 / 共23页
自动售货机设计和实现.docx_第12页
第12页 / 共23页
自动售货机设计和实现.docx_第13页
第13页 / 共23页
自动售货机设计和实现.docx_第14页
第14页 / 共23页
自动售货机设计和实现.docx_第15页
第15页 / 共23页
自动售货机设计和实现.docx_第16页
第16页 / 共23页
自动售货机设计和实现.docx_第17页
第17页 / 共23页
自动售货机设计和实现.docx_第18页
第18页 / 共23页
自动售货机设计和实现.docx_第19页
第19页 / 共23页
自动售货机设计和实现.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

自动售货机设计和实现.docx

《自动售货机设计和实现.docx》由会员分享,可在线阅读,更多相关《自动售货机设计和实现.docx(23页珍藏版)》请在冰点文库上搜索。

自动售货机设计和实现.docx

自动售货机设计和实现

大学实验报告

 

课程名称:

数字系统现场集成技术

实验项目名称:

实验四(自动售货机设计和实现)

学院:

专业:

指导教师:

报告人:

学号:

班级:

实验时间:

实验报告提交时间:

教务部制

一、实验目的与要求:

基本要求:

该实验为团队协作,2人一个小组。

可以对3种不同种类的货物进行自动售货,价格分别为A=4.00,B=2.50,C=1.00。

售货机可以接受10元,5元,1元三种硬币(即有三种输入信号SY,WY,IY),并且在7段数码管(二位代表元,一位代表角)显示已投入的总钱数,选择货物的输入信号Ia,Ib,Ic,输出指示信号为Sa,Sb,Sc分别表示售出相应的货物,同时输出的信号yuan,jiao代表找零,并显示在7段数码管上。

高级要求(可选):

VGA显示3种货物图片及其价格,鼠标点击购买数量(1-9)后显示总价,安规格说明2中的button2-button4输入硬币,VGA显示已投入的总钱数,鼠标点击购买后,显示找零数目,购买物品闪烁,交易完成。

规格说明:

∙按一下button1按钮,表示购买货物A,第一个LED灯亮;按两下button1按钮,表示购买货物B,第二个LED灯亮;按三下button1按钮,表示购买货物C,第三个LED灯亮,同时7段数码管显示所要购买货物的价格。

∙LED灯亮后,开始输入硬币。

button2按一下,输入10元,按两下,输入二十元,以此类推;Button3按一下输入5元,按两下输入10元,以此类推;button4按一下输入1元,按两下输入2元,以此类推。

7段数码管显示已投入的总钱数,再次按下button1键,7段数码管显示找零数目,同时指示货物的LED灯熄灭。

∙如果投入的钱币不够就按下button1键确认购买,数码管显示“ER”。

∙本实验使用FPGA板:

Sparant6XC6SLX16CSG324C(建project时,需要选择该芯片的型号)。

 

二、实验过程与代码:

1、顶层代码:

moduletop(

inputclk,

inputrst,

input[4:

0]btn,

output[3:

0]an,

output[7:

0]seg,

output[2:

0]led

);

wireclk,rst;

wire[7:

0]first_seg,second_seg,third_seg;

wire[4:

0]btn_down;

seg_drvv1(

.clk(clk),

.rst(rst),

.first_seg(first_seg),

.second_seg(second_seg),

.third_seg(third_seg),

.an(an),

.seg(seg)

);

mainv2(

.clk(clk),

.rst(rst),

.btn_down(btn_down),

.first_seg(first_seg),

.second_seg(second_seg),

.third_seg(third_seg),

.led(led)

);

btn_scanv3(

.clk(clk),

.rst(rst),

.btn(btn),

.btn_down(btn_down)

);

Endmodule

2、数码管驱动:

moduleseg_drv(

inputclk,

inputrst,

input[7:

0]first_seg,

input[7:

0]second_seg,

input[7:

0]third_seg,

//input[7:

0]forth_seg,

outputreg[3:

0]an,

outputreg[7:

0]seg

);

localparam[1:

0]s0=2'b00,

s1=2'b01,

s2=2'b10,

s3=2'b11;

reg[1:

0]state;

always@(posedgeclk,posedgerst)

begin

if(rst)

begin

an<=4'b1111;

seg<=8'b1111_1111;

state<=s0;

end

else

begin

case(state)

s0:

begin

an<=4'b1110;

seg<=first_seg;

if(ms_up)

state<=s1;

else

state<=state;

end

s1:

begin

an<=4'b1101;

seg<=second_seg;

if(ms_up)

state<=s2;

else

state<=state;

end

s2:

begin

an<=4'b1011;

seg<=third_seg;

if(ms_up)

state<=s3;

else

state<=state;

end

s3:

begin

an<=4'b0111;

seg<=8'b1111_1111;

if(ms_up)

state<=s0;

else

state<=state;

end

endcase

end

end

reg[17:

0]ms_cnt;

regms_up;

always@(posedgeclk,posedgerst)

begin

if(rst)

begin

ms_cnt<=0;

ms_up<=0;

end

else

begin

if(ms_cnt==200000)

begin

ms_cnt<=0;

ms_up<=1;

end

else

begin

ms_cnt<=ms_cnt+1'b1;

ms_up<=0;

end

end

end

endmodule

3、按键扫描与消抖:

modulebtn_scan(

inputclk,

inputrst,

input[3:

0]btn,

outputreg[3:

0]btn_down

);

localparam[1:

0]s0=2'b00,

s1=2'b01,

s2=2'b10;

reg[1:

0]state;

reg[3:

0]btn_reg;

always@(posedgeclk,posedgerst)

begin

if(rst)

begin

btn_down<=4'b0000;

state<=s0;

end

else

begin

case(state)

s0:

begin

btn_down<=4'b0000;

if(btn)

state<=s1;

else

state<=s0;

end

s1:

begin

if(cnt_done)

begin

if(btn)

begin

state<=s2;

btn_reg<=btn;

end

else

state<=s0;

end

else

state<=s1;

end

s2:

begin

if(btn==4'b0000)

begin

btn_down<=btn_reg;

state<=s0;

end

else

begin

btn_down<=btn_down;

state<=s2;

end

end

endcase

end

end

reg[20:

0]cnt;

regcnt_done;

always@(posedgeclk,posedgerst)

begin

if(rst)

begin

cnt<=21'b0;

cnt_done<=1'b0;

end

elseif(state==s1)

begin

cnt<=cnt+1'b1;

if(cnt==21'd2000000)

begin

cnt<=21'b0;

cnt_done<=1'b1;

end

end

else

begin

cnt<=21'b0;

cnt_done<=1'b0;

end

end

endmodule

4、主程序code:

modulemain(

inputclk,

inputrst,

input[3:

0]btn_down,

outputreg[7:

0]first_seg,

outputreg[7:

0]second_seg,

outputreg[7:

0]third_seg,

outputreg[2:

0]led

);

localparam[2:

0]s0=3'b000,s1=3'b001,s2=3'b010,s3=3'b011,s4=3'b100,s5=3'b101;

reg[2:

0]state;

reg[3:

0]money0,money1;

reg[3:

0]price;

reg[4:

0]change;

reg[3:

0]change1,change0;

always@(posedgeclk,posedgerst)

begin

if(rst)

begin

led<=3'b000;

money0<=0;

money1<=0;

change<=0;

price<=0;

state<=s0;

end

else

begin

case(state)

s0:

begin

led<=3'b000;

if(btn_down[0]==1)

state<=s1;

else

state<=s0;

end

s1:

begin

led<=3'b100;

price<=1;

money0<=0;

money1<=0;

change<=0;

if(btn_down[0]==1)

state<=s2;

elseif(btn_down[3:

1])

state<=s4;

else

state<=s1;

end

s2:

begin

led<=3'b010;

price<=2.5;

money0<=0;

money1<=0;

change<=0;

if(btn_down[0]==1)

state<=s3;

elseif(btn_down[3:

1])

state<=s4;

else

state<=s2;

end

s3:

begin

led<=3'b001;

price<=4;

money0<=0;

money1<=0;

change<=0;

if(btn_down[0]==1)

state<=s1;

elseif(btn_down[3:

1])

state<=s4;

else

state<=s3;

end

s4:

begin

case(btn_down[3:

1])

3'b001:

money1<=money1+1;

3'b010:

begin

money0=money0+5;

if(money0>=10)

begin

money1<=money1+1;

money0<=money0-10;

end

else

money1<=money1;

end

3'b100:

begin

money0<=money0+1;

if(money0>=9)

begin

money1<=money1+1;

money0<=0;

end

else

money1<=money1;

end

endcase

if(btn_down[0]==1)

state<=s5;

else

state<=s4;

end

s5:

begin

if((money1*10+money0)>=price)

begin

change<=money1*10+money0-price;

if(change>=20)

begin

change1<=2;

change0<=change-20;

end

elseif(change>=10)

begin

change1<=1;

change0<=change-10;

end

else

begin

change1<=0;

change0<=change;

end

end

else

change<=5'b01110;

if(btn_down[3:

0])

state<=s0;

else

state<=s5;

end

endcase

end

end

//译码

always@(posedgeclk,posedgerst)

begin

if(state==s0)

begin

third_seg<=8'b0000_0011;

second_seg<=8'b0000_0010;

first_seg<=8'b0000_0011;

end

elseif(state==s1)

begin

third_seg<=8'b0000_0011;

second_seg<=8'b1001_1110;

first_seg<=8'b0000_0011;

end

elseif(state==s2)

begin

third_seg<=8'b0000_0011;

second_seg<=8'b0010_0100;

first_seg<=8'b0100_1001;

end

elseif(state==s3)

begin

third_seg<=8'b0000_0011;

second_seg<=8'b1001_1000;

first_seg<=8'b0000_0011;

end

elseif(state==s4)

begin

case(money0)

4'b0000:

second_seg<=8'b0000_0010;

4'b0001:

second_seg<=8'b1001_1110;

4'b0010:

second_seg<=8'b0010_0100;

4'b0011:

second_seg<=8'b0000_1100;

4'b0100:

second_seg<=8'b1001_1000;

4'b0101:

second_seg<=8'b0100_1000;

4'b0110:

second_seg<=8'b0100_0000;

4'b0111:

second_seg<=8'b0001_1110;

4'b1000:

second_seg<=8'b0000_0000;

4'b1001:

second_seg<=8'b0000_1000;

endcase

case(money1)

4'b0000:

third_seg<=8'b0000_0011;

4'b0001:

third_seg<=8'b1001_1111;

4'b0010:

third_seg<=8'b0010_0101;

4'b0011:

third_seg<=8'b0000_1101;

4'b0100:

third_seg<=8'b1001_1001;

4'b0101:

third_seg<=8'b0100_1001;

4'b0110:

third_seg<=8'b0100_0001;

4'b0111:

third_seg<=8'b0001_1111;

4'b1000:

third_seg<=8'b0000_0001;

4'b1001:

third_seg<=8'b0000_1001;

endcase

first_seg<=8'b0000_0011;

end

elseif(state==s5)

begin

if(change==5'b01110)

begin

third_seg<=8'b0000_0011;

second_seg<=8'b0110_0001;

first_seg<=8'b0110_0001;

end

else

begin

case(change0)

4'b0000:

second_seg<=8'b0000_0010;

4'b0001:

second_seg<=8'b1001_1110;

4'b0010:

second_seg<=8'b0010_0100;

4'b0011:

second_seg<=8'b0000_1100;

4'b0100:

second_seg<=8'b1001_1000;

4'b0101:

second_seg<=8'b0100_1000;

4'b0110:

second_seg<=8'b0100_0000;

4'b0111:

second_seg<=8'b0001_1110;

4'b1000:

second_seg<=8'b0000_0000;

4'b1001:

second_seg<=8'b0000_1000;

4'he:

second_seg<=8'b0110_0000;

endcase

case(change1)

4'b0000:

third_seg<=8'b0000_0011;

4'b0001:

third_seg<=8'b1001_1111;

4'b0010:

third_seg<=8'b0010_0101;

4'b0011:

third_seg<=8'b0000_1101;

4'b0100:

third_seg<=8'b1001_1001;

4'b0101:

third_seg<=8'b0100_1001;

4'b0110:

third_seg<=8'b0100_0001;

4'b0111:

third_seg<=8'b0001_1111;

4'b1000:

third_seg<=8'b0000_0001;

4'b1001:

third_seg<=8'b0000_1001;

endcase

if(led[1]==1)

first_seg<=8'b0100_1001;

else

first_seg<=8'b0000_0011;

end

end

end

endmodule

三、实验结果:

 

买货物2,价格2.5,投币15,找零12.5

金币不够显示为错误

深圳大学学生实验报告用纸

四、实验结论:

通过此次实验加深了对数码管驱动以及按键扫描与消抖工作原理的的运用,对各个模块搭建系统也有了新的认识。

 

指导教师批阅意见:

成绩评定:

指导教师签字:

年月日

备注:

注:

1、报告内的项目或内容设置,可根据实际情况加以调整和补充。

2、教师批改学生实验报告时间应在学生提交实验报告时间后10日内。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2