教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 高等教育 >

数电课程设计 - 出租车计费(2)

来源:网络收集 时间:2026-09-14
导读: case(courrent_state) IDLE:begin next_state always@(next_state) //将状态转化为stop的输出 begin case(next_state) IDLE:begin stop1=0;stop2=0;stop3=0;stop4=0;stop5=0;end A:begin stop1=1;stop2=0;stop3=0;s

case(courrent_state)

IDLE:begin next_state<=A;end B:begin next_state<=C;end A:begin next_state<=B;end C:begin next_state<=D;end D:begin next_state<=E;end E:begin next_state<=A;end default:next_state<=IDLE; endcase end

always@(next_state) //将状态转化为stop的输出 begin case(next_state)

IDLE:begin stop1=0;stop2=0;stop3=0;stop4=0;stop5=0;end A:begin stop1=1;stop2=0;stop3=0;stop4=0;stop5=0;end B:begin stop1=0;stop2=1;stop3=0;stop4=0;stop5=0;end C:begin stop1=0;stop2=0;stop3=1;stop4=0;stop5=0;end D:begin stop1=0;stop2=0;stop3=0;stop4=1;stop5=0;end E:begin stop1=0;stop2=0;stop3=0;stop4=0;stop5=1;end

default:begin stop1=0;stop2=0;stop3=0;stop4=0;stop5=0;end endcase end

/******************************************/ endmodule

仿真结果:

由上图可以看出根据状态机对按键stop的检测可以将stop按下的次数转换为stop1--stop5的值输出。

5

总的程序模块:

endmodulemodule texi(clk,clk1,start,start1,stop,reset,s1,s2,s3,s4,s5); input clk,clk1,start,stop,reset,start1; output[3:0] s1,s2,s3,s4,s5; reg start_1,start1_1,stop_1,reset1; reg[3:0]s1,s2,s3,s4,s5; reg[2:0] A;

reg[9:0]s,t,cost_s,cost_t,cost;

reg[9:0]s_1,t1,cost_s1,cost_t1,cost1; //用来存放中间变量 /***************************************/

initial //数据初始化 begin

s1=0; s2=0; s3=0; s4=0; s5=0; s=0; t=0;

cost_s=0; cost_t=0; cost=0; A=3'b111; end

/********************************/

always@(posedge clk ) //按键消抖 begin start_1<=start; start1_1<=start1; stop_1=stop; reset1<=reset; end

/*************************************/

always@(negedge clk) //状态判断 begin if(start_1) A=3'b000; if(start1_1) A=3'b001; if(reset1) A=3'b111; if(stop_1) //在stop键按下的情况下对显示状态进行选择 begin

6

if(stop1)A=3'b110; if(stop2)A=3'b010; if(stop3)A=3'b011; if(stop4)A=3'b100; if(stop5)A=3'b101; end end

/***************************/

seqdet(clk,stop,stop1,stop2,stop3,stop4,stop5); //状态机调用 /***************************/

div1(clk,clk1_1); div2(clk1,clk2_1);

/***************************/

always@(posedge clk2_1) begin

if(A==3'b000) begin s=s+1; if(s<31) cost_s=80; else cost_s=cost_s+2; end

if(A==3'b111) begin s=0;

cost_s=0; end end

/*****************************/

always@(posedge clk1_1) begin

if(A==3'b001) begin t=t+10;

cost_t=cost_t+1; end

if(A==3'b111) begin t=0;

cost_t=0; end end

/****************************/

//f对时钟做分频处理 //路程计费程序 //时间计费程序 7

always@(posedge clk) //状态判断,现实选择模块 begin

cost=cost_s+cost_t; case(A)

3'b011: //显示走过的路程 begin s_1=s; s1=0;

s2=s_1%4'b1010; s_1=s_1/4'b1010; s3=s_1%4'b1010; s_1=s_1/4'b1010; s4=s_1%4'b1010; s5=s_1/4'b1010; end

3'b100: begin

cost_s1=cost_s; s1=0;

s2=cost_s1%4'b1010; cost_s1=cost_s1/4'b1010; s3=cost_s1%4'b1010; cost_s1=cost_s1/4'b1010; s4=cost_s1%4'b1010; s5=cost_s1/4'b1010; end

3'b101: begin t1=t; s1=0;

s2=t1%4'b1010; t1=t1/4'b1010; s3=t1%4'b1010; t1=t1/4'b1010; s4=t1%4'b1010; s5=t1/4'b1010; end

3'b110: begin

cost_t1=cost_t; s1=0;

s2=cost_t1%4'b1010; cost_t1=cost_t1/4'b1010; s3=cost_t1%4'b1010;

//显示路程收费 //显示等待时间 //显示时间计费 8

cost_t1=cost_t1/4'b1010; s4=cost_t1%4'b1010; s5=cost_t1/4'b1010; end

3'b111: //数据清零 begin cost=0; s1=0; s2=0; s3=0; s4=0; s5=0; end

default: //其他情况均显示总费用 begin

cost1=cost; s1=0;

s2=cost1%4'b1010; cost1=cost1/4'b1010; s3=cost1%4'b1010; cost1=cost1/4'b1010; s4=cost1%4'b1010; s5=cost1/4'b1010; end

endcase end

endmodule

仿真结果:

9

五.实验心得:

此次数电课程设计我们做的是出租车计费器系统,通过查阅参考资料明白了具体实现步骤,在老师的指导下进行编程、仿真、以及硬件连接显示,最终实现了出租车计费器系统的功能。刚开始编程时由于整体放在一块编,结果很繁琐并且编译出现了很多错误,后来同学建议把程序分成几个模块编写,这样不容易出错,这样编写果然容易多了并且终于编译仿真通过。

通过在QuartusⅡ软件下进行的模拟仿真,并进行相应的硬件下载调试,证明所设计的系统完成了出租车计费器的功能,各项技术指标符合预定标准,具有一定实用性。如果将该设计再结合到实际应用中,那么,只需改变设计中计费要求,就可以应用到出租车上。另外,如果再任意输入该出租车计价器的计费标准,那么,它的适用范围可能就更广泛了。本次课程设计还是比较有成就感的,因为遇到一些很棘手的问题,最终解决之后感觉很好,还学到一些之前没学到的东西。 …… 此处隐藏:1362字,全部文档内容请下载后查看。喜欢就下载吧 ……

数电课程设计 - 出租车计费(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/604560.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)