基于verilog语言的出租车计费器

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1时间分频:modulediv(clk_50M,clk);//端口的定义inputclk_50M;//总的时钟是50Moutputclk;//分频后输的时钟regclk;reg[31:0]count;//32位的计数器always@(posedgeclk_50M)//异步复位beginif(count==32'd25_000000)//判断计时器记到了25_000000吗begincount=32'd0;//计到25_000000计数器清零clk=~clk;//输出的时钟取反end//endbeginelsecount=count+1'd1;//没计到25_000000计数器加一end//endalwaysendmodule//结束分频模块2速度分频;modulesududiv(op,clk_50M,clk,reset);//端口的定义inputclk_50M,reset;//总的时钟是50Minput[2:0]op;outputclk;//分频后输的时钟regclk;reg[31:0]count;//32位的计数器always@(posedgeclk_50Mornegedgereset)//异步复位beginif(!reset)beginclk='d0;count=32'd0;endelsebegincase(op)3'b001:if(count==32'd50_000000)//判断计时器记到了25_000000吗begincount=32'd0;//计到25_000000计数器清零clk=~clk;//输出的时钟取反end//endbeginelsecount=count+1'd1;//没计到25_000000计数器加一3'b010:if(count==32'd40_000000)//判断计时器记到了25_000000吗begincount=32'd0;//计到25_000000计数器清零clk=~clk;//输出的时钟取反end//endbeginelsecount=count+1'd1;//没计到25_000000计数器加一3'b011:if(count==32'd30_000000)//判断计时器记到了25_000000吗begincount=32'd0;//计到25_000000计数器清零clk=~clk;//输出的时钟取反end//endbeginelsecount=count+1'd1;//没计到25_000000计数器加一default:clk=clk;endcaseend//end//endalwaysendmodule//结束分频模块3系统时间计数:modulexttimemokuai(clk,s,m,);//端口的定义inputclk;output[7:0]s;//输出的秒output[7:0]m;//输出的分reg[7:0]s;reg[7:0]m;always@(posedgeclk)//异步复位beginif(s[3:0]==9)//秒的低四位是9begins[3:0]=4'd0;//清零if(s[7:4]==5)//秒的高四位是5begins[7:4]=4'd0;//清零if(m[3:0]==9)//分的低四位是9beginm[3:0]=4'd0;//清零if(m[7:4]==9)//分的高四位是9m[7:4]=4'd0;//清零elsem[7:4]=m[7:4]+1'd1;//分的高四位不是9加一endelsem[3:0]=m[3:0]+1'd1;//分的低四位不是9加一endelses[7:4]=s[7:4]+1'd1;//秒的高四位不是5加一endelses[3:0]=s[3:0]+1'd1;//秒的低四位不是9加一end//endalways//产生time_enable信号。endmodule//结束计时模块4等候时间计数:moduletimemokuai(clk,reset,start,s,m);//端口的定义inputclk,reset,start;output[7:0]s;//输出的秒output[7:0]m;//输出的分reg[7:0]s;reg[7:0]m;always@(posedgeclkornegedgereset)//异步复位beginif(!reset)//低电平有效begin//复位s=8'd0;m=8'd0;endelseif(!start)//start信号低电平有效beginif(s[3:0]==9)//秒的低四位是9begins[3:0]=4'd0;//清零if(s[7:4]==5)//秒的高四位是5begins[7:4]=4'd0;//清零if(m[3:0]==9)//分的低四位是9beginm[3:0]=4'd0;//清零if(m[7:4]==9)//分的高四位是9m[7:4]=4'd0;//清零elsem[7:4]=m[7:4]+1'd1;//分的高四位不是9加一endelsem[3:0]=m[3:0]+1'd1;//分的低四位不是9加一endelses[7:4]=s[7:4]+1'd1;//秒的高四位不是5加一endelses[3:0]=s[3:0]+1'd1;//秒的低四位不是9加一end//endalwaysendendmodule//结束计时模块5里程计数:moduledistancemokuai(clk,start,reset,distance);//端口的定义inputclk,start,reset;output[7:0]distance;//输出的公里reg[7:0]distance;always@(posedgeclkornegedgereset)//异步复位beginif(!reset)//低电平复位begindistance=8'd0;endelseif(start)//start高电平有效beginif(distance[3:0]==9)//判断distance的低四位计到了9没有begindistance[3:0]=4'd0;//计到9清零if(distance[7:4]==9)//判断distance的高四位计到了9没有distance[7:4]=4'd0;//计到9清零elsedistance[7:4]=distance[7:4]+1'd1;//distance的高四位没有计到9的时候加一endelsedistance[3:0]=distance[3:0]+1'd1;//distance的低四位没有计到9的时候加一end//endstartend//endalways//*产生distance_enable信号*//endmodule//结束计程模块6费用计算模块:modulefee(clk,bianjia,xuanze,juli,shijian,fee,fee1,danjia);inputjuli,shijian,clk,bianjia,xuanze,danjia;wire[7:0]r;reg[7:0]r1;reg[7:0]r2;reg[7:0]p;wire[7:0]p1;output[7:0]fee;output[7:0]fee1;wire[7:0]juli;wire[7:0]shijian;reg[7:0]x1;reg[7:0]x2;always@(posedgeclk)beginif(bianjia)beginp=p+1;endelsebeginp=p-1;endendalways@(juliorshijian)beginx1=juli[7:4]*10+juli[3:0];if(juli=8'd3)r1=6;elsebeginif(xuanze)beginr1=(x1-3)*(p+1)+6;endelsebeginr1=(x1-3)*(p+2)+6;endend//endelsex2=shijian[7:4]*10+shijian[3:0];r2=x2*1;endassignp1=xuanze?p+1:p+2;assignr=danjia?p1:r1+r2;assignfee1[7:4]=r/1000;assignfee1[3:0]=(r-1000*fee1[7:4])/100;assignfee[7:4]=(r-100*fee1)/10;assignfee[3:0]=r%10;endmodule7系统和等候时间控制输出模块:moduletimecontrol(timecontrol,xts,xtm,s,m,xss,xsm);input[7:0]s;//输入的秒input[7:0]m;//输入的分。input[7:0]xts;//输入的秒input[7:0]xtm;//输入的分。output[7:0]xss;//输出的秒output[7:0]xsm;//输出的分wire[7:0]xss;wire[7:0]xsm;inputtimecontrol;assignxss=timecontrol?xts:s;assignxsm=timecontrol?xtm:m;endmodule8费用高八位和里程的输出控制:modulefeecontrol(fee1,distance,shuchu,panduan);input[7:0]fee1;//输入的秒input[7:0]distance;//输入的分。output[7:0]shuchu;//输出wire[7:0]shuchu;inputpanduan;assignshuchu=panduan?distance:fee1;endmodule9总体显示模块;modulescan_led(distance,s,m,fee,segdat1,segdat2,segdat3,segdat4,segdat5,segdat6,segdat7,segdat8);//inputoutclk;input[7:0]distance,fee;//输入的公里,费用。input[7:0]s;//输入的秒input[7:0]m;//输入的分。wire[3:0]dispdat1,dispdat2,dispdat3,dispdat4,dispdat5,dispdat6,dispdat7,dispdat8;output[7:0]segdat1,segdat2,segdat3,segdat4,segdat5,segdat6,segdat7,segdat8;//reg[3:0]dispdat1,dispdat2,dispdat3,dispdat4,dispdat5,dispdat6,dispdat7,dispdat8;reg[2:0]count_reg;reg[7:0]segdat1,segdat2,segdat3,segdat4,segdat5,segdat6,segdat7,segdat8;reg[3:0]count;reg[7:0]min,sec,dis,money;//////////////////////////////////assigndispdat8=fee[7:4];//qianshushiweiassigndispdat1=s[3:0];//miaodegeweiassigndispdat2=s[7:4];//miaodeshiweiassigndispdat3=m[3:0];//fendegeweiassigndispdat4=m[7:4];//fendeshiweiassigndispdat5=distance[3:0];//juligeweiassigndispdat6=distance[7:4];//julishiweiassigndispdat7=fee[3:0];//qianshugewei/////////////////////////miaodegewei///////////////////////////////////////always@(dispdat1)begincase(di

1 / 12
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功