太原科技大学:名字起个什么电子课程设计——————出租车计费器学院:专业班级:姓名:学号:指导老师:2009年12月11日太原科技大学:名字起个什么1一、设计任务与要求设计一个出租车计费器,具体要求如下:1.能实现计费功能,计费标准为:按行驶里程收费,起步价为7.00元,在行驶3公里之后,按每公里2.2元计费,计费满20元之后按每公里3.3元计费,停车不计费。2.能置起步价。3.能实现汽车启动、停止、暂停、车速等状态。4.设计动态扫描电路,将路程和收费显示出来。二、总体框图速度控制路程控制计费模块扫描显示模块太原科技大学:名字起个什么2三、功能模块1.速度控制clkresetstartk[2..0]clkoutsudukongzhiinst6程序如下:LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;entitysudukongzhiisport(clk,reset,start:instd_logic;k:instd_logic_vector(2downto0);clkout:outstd_logic);endsudukongzhi;ARCHITECTUREFUNOFsudukongzhiISsignalcount1:std_logic_vector(1downto0);signaltmpclk,clks:std_logic;signalkinside:std_logic_vector(2downto0);beginkinside=000-k;clks_label:process(reset,clk)variablecount2:std_logic_vector(2downto0);beginifreset='0'thencount2:=000;elsif(clk'eventandclk='1')thenifstart='1'thenifcount2=kinsidethencount2:=000;endif;ifnot(k=000)thencount2:=count2+1;endif;太原科技大学:名字起个什么3ifcount2=001thentmpclk=nottmpclk;endif;endif;endif;endprocess;clkout=tmpclk;endFUN;仿真图如下:功能说明:通过调节K[2..0]来实现调节速度,当都为0时暂停,都为1时最快,reset为0时有效,start为1时有效。2.路程控制clkresetlucheng1[3..0]lucheng2[3..0]lucheng3[3..0]luchengkongzhiinst1程序如下:LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;USEIEEE.STD_LOGIC_ARITH.ALL;ENTITYluchengkongzhiISPORT(clk,reset:instd_logic;lucheng1:outstd_logic_vector(3downto0);lucheng2:outstd_logic_vector(3downto0);lucheng3:outstd_logic_vector(3downto0));endluchengkongzhi;ARCHITECTUREFUNOFluchengkongzhiIS太原科技大学:名字起个什么4beginprocess(clk,reset)variablemm:std_logic_vector(11downto0);beginifreset='0'thenmm:=000000000000;elsifclk'eventandclk='1'thenifmm(3downto0)=1001thenmm:=mm+7;elsemm:=mm+1;endif;ifmm(7downto4)=1010thenmm:=mm+01100000;endif;ifmm(11downto8)=1010thenmm:=mm+011000000000;endif;endif;lucheng1=mm(3downto0);lucheng2=mm(7downto4);lucheng3=mm(11downto8);endprocess;endFUN;仿真图如下:功能说明:加法器,由clk控制,实现路程的累加,reset为0有效。太原科技大学:名字起个什么53.计费模块clkresetjudge2[3..0]judge3[3..0]jifei1[3..0]jifei2[3..0]jifei3[3..0]jifei4[3..0]jifeimokuaiinst程序如下:LIBRARYIEEE;USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;USEIEEE.STD_LOGIC_ARITH.ALL;ENTITYjifeimokuaiISPORT(clk,reset:instd_logic;judge2:instd_logic_vector(3downto0);judge3:instd_logic_vector(3downto0);jifei1:outstd_logic_vector(3downto0);jifei2:outstd_logic_vector(3downto0);jifei3:outstd_logic_vector(3downto0);jifei4:outstd_logic_vector(3downto0));endjifeimokuai;ARCHITECTUREFUNOFjifeimokuaiISSIGNALen:STD_LOGIC;signalshoufei:std_logic_vector(7downto0);signalshoufeijishu:std_logic_vector(15downto0);beginshoufei=00110011when((shoufeijishu(15)='1')or(shoufeijishu(14)='1')or(shoufeijishu(13)='1'))else00100010;en='0'whenjudge3=0000andjudge2(3downto2)=00and((judge2(1)='0')or(judge2(1)='1'andjudge2(0)='0'))else'1';process(clk,reset)variablemm:std_logic_vector(15downto0);beginifreset='0'then太原科技大学:名字起个什么6mm:=0000011100000000;elsifclk'eventandclk='1'thenifen='1'thenmm:=mm+shoufei;endif;ifmm(3)='1'and(not(mm(2downto1)=00))thenmm:=mm+6;endif;ifmm(7)='1'and(not(mm(6downto5)=00))thenmm:=mm+01100000;endif;ifmm(11)='1'and(not(mm(10downto9)=00))thenmm:=mm+011000000000;endif;ifmm(15downto12)=1010thenmm:=mm+0110000000000000;endif;endif;jifei1=mm(3downto0);jifei2=mm(7downto4);jifei3=mm(11downto8);jifei4=mm(15downto12);shoufeijishu=mm;endprocess;endFUN;仿真图如下:太原科技大学:名字起个什么7功能说明:由clk控制,实现计费累加,reset为0有效,初始置数为7.00元,满203公里之后没公里2.20元,满20元之后,每公里3.30元。4.分频器clkclkoutDIVinst5程序如下:LIBRARYieee;USEieee.std_logic_1164.all;useieee.std_logic_unsigned.all;ENTITYDIVISPORT(clk:INSTD_LOGIC;clkout:OUTSTD_LOGIC);太原科技大学:名字起个什么8ENDDIV;ARCHITECTUREONEOFDIVISBEGINPROCESS(clk)VARIABLEcnt:INTEGERrange0to100000;VARIABLEtmp:STD_LOGIC;BEGINIF(clk'EVENTANDclk='1')THENIF(cnt=9999)THENcnt:=0;tmp:=nottmp;ELSEcnt:=cnt+1;ENDIF;ENDIF;clkout=tmp;ENDPROCESS;ENDone;仿真图如下:5.扫描显示模块clkp8[3..0]p7[3..0]p6[3..0]p5[3..0]p4[3..0]p3[3..0]p2[3..0]p1[3..0]xuanze[7..0]shuzhi[7..0]xianshimokuaiinst7程序如下:LIBRARYIEEE;太原科技大学:名字起个什么9USEIEEE.STD_LOGIC_1164.ALL;USEIEEE.STD_LOGIC_UNSIGNED.ALL;entityxianshimokuaiisport(clk:instd_logic;p8:instd_logic_vector(3downto0);p7:instd_logic_vector(3downto0);p6:instd_logic_vector(3downto0);p5:instd_logic_vector(3downto0);p4:instd_logic_vector(3downto0);p3:instd_logic_vector(3downto0);p2:instd_logic_vector(3downto0);p1:instd_logic_vector(3downto0);xuanze:outstd_logic_vector(7downto0);shuzhi:outstd_logic_vector(7downto0));endentity;ARCHITECTUREFUNOFxianshimokuaiISsignalcount:std_logic_vector(2downto0);signaltmp:std_logic_vector(3downto0);signalchoicein:std_logic_vector(7downto0);signaldatain:std_logic_vector(7downto0);beginclk1_label:process(clk)beginifclk'eventandclk='1'thencount=count+1;endif;endprocess;clk2_label:process(clk)beginifclk'eventandclk='0'thenxuanze=choicein;shuzhi(7downto1)=datain(7downto1);if(count=0110orcount=0010)thenshuzhi(0)='1';elseshuzhi(0)='0';endif;endif;endprocess;choicein=11111110whencount=000else11111101whencount=001else11111011whencount=010else11110111whencount=011else11101111whencount=100else太原科技大学:名字起个什么1011011111whencount=1