//此专题为我找的一些题目做过的fpga小实训
出租车计费器
设计要求:
 1. 能实现计费功能,计费标准为:按行驶里程收费,起步费为10.00元,
  并在车行3公里后再按2元/公里,当计费器计费达到或超过一定收费(如20元)时,
  每公里加收50%的车费,车停止不计费。
 2. 实现预置功能:能预置起步费、每公里收费、车行加费里程。
 3. 实现模拟功能:能模拟汽车启动、停止、暂停、车速等状态。
 4. 设计动态扫描电路:将车费显示出来,有两位小数。
 5. 用Verilog语言设计符合上述功能要求的出租车计费器,并用层次化设计方法设计该电路。
 6. 各计数器的计数状态用功能仿真的方法验证,并通过有关波形确认电路设计是否正确。
 7. 完成电路全部设计后,通过系统实验箱下载验证设计的正确性。  计费器按里程收费,每100米开始一次计费。
设计代码:
moduleTaxi_prj(
						clk,
						rst_n,
						en,
						//delay,
						Mail_out,
						Cost_out
						);
	inputclk,rst_n;
	inputen;
	
	regflag;
	reg[9:0]delay;
	output[9:0]Mail_out;
	output[9:0]Cost_out;
	
	reg[9:0]mail_cnt;
	reg[9:0]cost_cnt;
	
	always@(posedgeclkornegedgerst_n)	
	begin
		if(!rst_n)
			mail_cnt<=9'd30;
		elseif(cost_cnt!=9'd10&&en==1&&flag==0)
			mail_cnt<=mail_cnt+1'b1;//100m
		elseif(flag==1)
			mail_cnt<=9'd30;
	end
	
	always@(posedgeclkornegedgerst_n)
	begin
		if(!rst_n)
			cost_cnt<=9'd10;
		elseif(flag==0&&en)begin
			if(cost_cnt<=9'd19)//8km
				cost_cnt<=cost_cnt+9'd2;//2yuan
			elseif(cost_cnt>=9'd20)
				begin
					cost_cnt<=cost_cnt+9'd3;//2yuan
				end
		end
		elseif(flag==1)
			cost_cnt<=9'd10;
			//mail_cnt<=9'd30;
	end
	
	always@(posedgeclkornegedgerst_n)
	begin
		if(!rst_n)begin
			delay<=9'd0;
			flag<=0;
		end
		elseif(en==0)begin//停车开始计数
			delay<=delay+9'd1;
			if(delay==9'd49)begin
				flag<=1;
			end
			else
				flag<=0;
		end
		
	end
	
	assignMail_out=mail_cnt;
	assignCost_out=cost_cnt;
	
endmodule
`timescale1ns/1ns
`defineclock_period20
moduleTaxi_prj_tb;
	regclk;
	regrst_n;
	regen;
	//wire[9:0]delay;
	wire[9:0]Mail_out;
wire[9:0]Cost_out;
	
	Taxi_prjTaxi_prj(
							.clk(clk),
							.rst_n(rst_n),
							.en(en),
						//	.delay(delay),
							.Mail_out(Mail_out),
							.Cost_out(Cost_out)
							);
	initialclk=1;
	always#(`clock_period/2)clk=~clk;
	
	initialbegin
		rst_n=1'b0;
		en=1;
		#(`clock_period*5);
		rst_n=1'b1;
		#(`clock_period*20);
		en=0;
		#(`clock_period*60);
		en=1;
		#(`clock_period*20);
		en=0;
		#(`clock_period*20);
		en=1;
		#(`clock_period*50);
		$stop;
	end
	
	
endmodule
备注:以实现基本要求,数码管显示使用顶层模块化设计
--------------------------------------------------------------