基于vhdl出租车计价器设计说明书.doc_第1页
基于vhdl出租车计价器设计说明书.doc_第2页
基于vhdl出租车计价器设计说明书.doc_第3页
基于vhdl出租车计价器设计说明书.doc_第4页
基于vhdl出租车计价器设计说明书.doc_第5页
已阅读5页,还剩50页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

摘要 该系统利用VHDL语言,以QuartusII软件作为开发平台,设计了出租车计程计价表,具有车型设置、起步里程设置、起步价设置、分时计价设置、里程显示、计费显示、计时显示、点阵数码管显示汉字及数字钟的报时及发光二极管花色显示等功能。并进行了程序仿真、动态扫描等步骤。关键词:VHDL语言、QuartusII软件、仿真目录一、设计任务说明- - 3-二、设计任务要求- 3 -三、设计内容- 4 -(一)里程计价部分- 4 -(二)计时部分- 8 -(三)数码管显示部分- 12 -(四)点阵显示部分- 17 -(五)数字钟的报时及发光二极管花色显示部分- 19 -(六)整体电路连接部分- 20 -四、整体电路图- 25 -五、硬件实验结果图- 27 -六、心得体会- 28 -一、设计任务说明设计一个出租车计程计价表,具有车型设置、起步里程设置、起步价设置、分时计价设置、里程显示、计费显示、计时显示、点阵数码管显示汉字及数字钟的报时及发光二极管花色显示等功能。出租车启动后,“里程显示”开始显示起步里程,当超出起步里程后,显示实际里程数据(单位:km),计费显示作相应的显示(单位:元)。二、设计任务要求1. 具有车型设置功能2具有起步里程设置功能3.具有起步价设置功能4.里程显示采用4位七段数码管,显示格式为.公里,高位灭零5.计费显示采用四位七段数码管,显示格式为.元,高位灭零6.起步里程后,白天(6:0023:00)每公里按1.20元计费,晚间(00:06:00)每公里按1.6元计费(每公里加收50%车费)7.显示复位功能8.内部具有时间计时功能,并可选择显示(计时或计费),时间显示采用8位七段数码管,显示格式为(小时)(分)(秒)9.按钮功能Sw4-修改计时中的小时Sw7-修改计时中的分钟Sw5-里程与计时之间的转换Sw6-显示字Sw8-复位按钮三、设计内容本次设计主要分六个部分第一部分:里程计价部分;第二部分:计时部分;第三部分:数码管显示部分;第四部分:点阵显示部分;第五部分:数字钟的报时及发光二极管花色显示部分;第六部分:整体电路连接部分(一) 里程计价部分1、 用到的模块图12、 各个模块的作用(1)Div模块作用:对芯片给的10MHZ的频率进行分频,然后传输给计数器A,提供扫描频率。(2)计数器A作用:对车轮传感器送来的车轮脉冲信号clk进行计数分频,车轮每转一圈送出一个脉冲。车每行驶100m,计数器A输出1个“100m脉冲信号oclk”,不同车型的车轮直径不一样,计数器A的分频系数也不一样(3)计数器B作用:对输入的100m脉冲oclk进行累加;在开始时输出起步里程数据,而当超出起步里程时自动输出实际公里数据给译码/动态扫描模块:每计满500m路程送出1个脉冲clkout给计数器C。(4)计数器C作用:实现步长可变(即单价可调)的累加计数;分时计价控制端“hourin”输入信号为0时,每500m计费0.6元;分时计价控制端“hourin”输入信号为1时,每500m计费0.9元。 3、各个模块的vhdl文件及仿真(1)Div模块的vhdl文件及仿真LIBRARY ieee; USE ieee.std_logic_1164.ALL;USE ieee.std_logic_unsigned.ALL; use ieee.std_logic_arith.all; ENTITY div IS PORT (clk_sys: IN std_logic;clk: OUT std_logic;clk_scan:out std_logic); END div;ARCHITECTURE a OF div ISsignal q: std_logic_vector(23 DOWNTO 0);BEGIN PROCESS (clk_sys)BEGINif(clk_sysevent and clk_sys = 0) then q = q + 1;系统脉冲每来一次下降沿,q加1end if;clk = q(18); clk_scan=q(9);把q的18位上的数据送入clk,把q的9位上的数据送入clkend process;end a;仿真波形如图2(注:为方便仿真,在此 clk = q(4); clk_scan=q(2); ):图2(2)计数器A的vhdl文件及仿真library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity cnt_A is -实体取名cnt_Aport( -端口描述clk:in std_logic; -输入信号clk为来自车轮传感器的脉冲信号start:in std_logic; -输入信号start为启动信号(即使能信号)cartype:in std_logic_vector (1 downto 0); -输入信号cartype为DIP_A的车型设置码oclk:out std_logic); -oclk为百米脉冲输出信号end cnt_A;architecture behave of cnt_A is -结构体名称behavesignal mode : std_logic_vector (5 downto 0); -mode为分频系数(内部信号)signal temp: std_logic_vector(5 downto 0); -temp为6位,记录计数值用beginmode=111100 when cartype=00 else -520mm,/61分频111010 when cartype=01 else -540 mm,/59分频111000 when cartype=10 else -560 mm,/57分频110110; -580 mm,/55分频process (start,clk)beginif rising_edge (clk) then -若clk的上升沿来到,则if start =1 then -若有start=1,则if temp=(mode) then -若temp=(mode)(计数模值),则temp0); -temp=“000000”(同步复零)else -否则temp=temp+1; -加1计数end if;end if;end if;end process;oclk=1 when (temp=mode) else0; -当temp=mode时oclk=1,否则=0end behave;仿真波形如图3(注:为方便仿真,在此mode=000011 when cartype=00):图3(3)计数器B的vhdl文件及仿真library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity cnt_B is -实体名cnt_B,500km路程出1个clkout脉冲的分频模块port(reset:in std_logic;clkin: in std_logic; -100m脉冲信号作为输入的信号clkindip: in std_logic_vector (2 downto 0); -用dip设置起步里程clkout: out std_logic; -500m脉冲输出信号clkoutlength: out std_logic_vector (12 downto 0);-计数位长13位,最大计999.9kmend entity;architecture two of cnt_B issignal licheng: std_logic_vector ( 12 downto 0); -13位内部信号licheng;存放起步里程signal temp0: std_logic_vector (12 downto 0); -13位内部信号temp0存放百米脉冲累计数signal temp1: std_logic_vector (3 downto 0); -4位内部信号temp1存放摸5计数器计数值beginwith dip selectlicheng=conv_std_logic_vector (30,13) when 000, -000档:30100m=3kmconv_std_logic_vector (40,13) when 001, -001档:40100m=4kmconv_std_logic_vector (50,13) when 010, -010档:50100m=5kmconv_std_logic_vector (60,13) when 011, -011档:60100m=6kmconv_std_logic_vector (70,13) when 100, -100档:70100m=7kmconv_std_logic_vector (80,13) when 101, -101档:80100m=8kmconv_std_logic_vector (90,13) when 110, -110档:90100m=9kmconv_std_logic_vector (100,13) when others; -111档:100100m=10kmp1: process(clkin) -进程p1,实际计数值加法计数器的描述beginif(reset=0) then temp00);elsif rising_edge (clkin) then -若百米脉冲信号clkin有上升沿则temp0=licheng) then -若temp0=licheng(起步里程),则if (temp1=conv_std_logic_vector(4,4) then -temp1的值为4,则 temp10); -temp1复0,(即temp1的模为5,对应500m)else temp1=temp1+1; -否则,temp1的值加1end if;end if;end if;end process p2;clkout=1 when (temp1=conv_std_logic_vector (4,4) else0;-temp1的值为4时进位输出clkout为1length=licheng when (temp0=licheng) else temp0;-当temp0=licheng时,length显示licheng,否则显示实际计数值temp0end two;仿真波形如图4:图4(4)计数器C的vhdl文件及仿真library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.numeric_std.all; -此句在Altera的MAX+plus下,无效use ieee.std_logic_arith.all;entity cnt_c is -实体名cnt_cport(hourin:in std_logic;reset:in std_logic;clkin:in std_logic; -500m脉冲作为输入的clkin信号dip:in std_logic_vector(1 downto 0); -用dip设置起步价格money:out std_logic_vector(12 downto 0); -价款(money)作为输出信号end cnt_c;architecture behave of cnt_c issignal qibu:std_logic_vector(12 downto 0); -13位内部信号qibu:存放起步价格数据signal temp0:std_logic_vector(12 downto 0);-13位内部信号temp0存放500m脉冲累计数begin with dip select -用dip的值选择起步价格qibuqibu=conv_std_logic_vector (50,13) when 00, -00档:5.0元起步价conv_std_logic_vector (60,13) when 01, -01档:6.0元起步价conv_std_logic_vector (80,13) when 10, -10档:8.0元起步价conv_std_logic_vector (100,13) when others; -11档:10.0元起步价process (clkin) -进程,500m脉冲加法计数器beginif(reset=0) then temp00);elsif rising_edge (clkin) then -若clkin有上升沿,则if hourin=0 then -若输入端hourin为0时,则temp0=temp0+0110; -temp0加6else temp0=temp0+1000; -否则temp0加9end if; end if;end process;money=qibu+temp0; -money显示起步加temp0end behave;仿真波形如图5:图5(二)计时部分1、用到的模块图62、各个模块的作用(1) Second模块作用:输入100m脉冲信号oclk作为“秒”输入;调“分”端口setmin用于设定“分”;对秒输入进行60分频,输出enmin即“分”信号;输出“秒”数据。(2) Minute模块作用:输入enmin即“分”信号;调“时”端口sethour用于设定“时”;对分输入进行60分频,输出enhour即“时”信号;输出“分”数据。(3) hour模块作用:输入enhour即“时”信号;输出“时”数据。3、各个模块的vhdl文件及仿真(1) Second模块的vhdl文件及仿真LIBRARY ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ENTITY second ISPORT(clk, reset,setmin : INSTD_LOGIC;enmin : OUTSTD_LOGIC;daout: out std_logic_vector (6 downto 0);END entity second;ARCHITECTURE fun OF second ISSIGNAL count: STD_LOGIC_VECTOR( 6 downto 0);SIGNAL enmin_1,enmin_2:STD_LOGIC;BEGINdaout = count;enmin_2=(not setmin and clk); -把setmin信号取反与clk信号相与结果送入enmin_2enmin=(enmin_1 or enmin_2); -把enmin_1信号与enmin_2信号相或结果送入enminprocess ( clk , reset , setmin) begin if (reset=0) then count = 0000000; -复位elsif (clk event and clk=1) then -判断上升沿if (count(3 downto 0)=1001) then -如果count低四位为9if (count 16#60#) then -如果count小于60if (count=1011001) then -如果count等于59 enmin_1=1; -“分”信号输出1个脉冲count=0000000; -秒归零ELSEcount=count+7; -秒数据加7end if;else count=0000000;end if;elsif (count 16#60#) then count = count+1;enmin_1=0 after 100 ns; -延时100ns后将0送入enmin_1else count=0000000; end if; end if;end process;END fun;仿真波形如图7:图7(2)Minute模块的vhdl文件及仿真LIBRARY ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ENTITY minute ISPORT(clk, clk1,reset,sethour : INSTD_LOGIC;enhour : OUTSTD_LOGIC;daout: out std_logic_vector (6 downto 0);END entity minute;ARCHITECTURE fun OF minute ISSIGNAL count: STD_LOGIC_VECTOR( 6 downto 0);SIGNAL enhour_1,enhour_2:STD_LOGIC;BEGINdaout = count; enhour_2=(not sethour and clk1);enhour=(enhour_1 or enhour_2);process ( clk,reset,sethour) begin if (reset=0) thencount = 0000000;elsif (clk event and clk=1) thenif (count(3 downto 0)=1001) thenif (count 16#60#) thenif (count=1011001) thenenhour_1=1; count=0000000; ELSEcount=count+7; end if;else count=0000000;end if;elsif(count 16#60#) then count = count + 1;enhour_1=0 after 100 ns;elsecount=0000000;end if;end if;end process;END fun;仿真波形如图8:图8(3)hour模块的vhdl文件及仿真LIBRARY ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ENTITY hour ISPORT(clk,reset: INSTD_LOGIC;daout: out std_logic_vector (5 downto 0);END entity hour;ARCHITECTURE fun OF hour ISSIGNAL count: STD_LOGIC_VECTOR( 5 downto 0);BEGINdaout = count;process ( clk,reset) begin if (reset=0) thencount = 000000;elsif (clk event and clk=1) thenif (count(3 downto 0)=1001) thenif (count 16#23#) thencount=count + 7; else count=000000;end if;elsif(count 16#23#) then count = count + 1;else count=000000;end if;end if;end process;END fun;仿真波形如图9:图9(三)数码管显示部分1. 用到的模块 图102. 各个模块的作用(1)BCD7模块:输入licheng信号和money信号转换成相应的七段数码管数据信号和地址信号输出(2)C47模块:输入second数据信号、minute数据信号和hour数据信号转换成相应的七段数码管数据信号和地址信号输出;当hour输入为236时,hourout输出为1,当hour输入为722时,hourout输出为0。3. 各个模块的程序(1) BCD7模块的程序及仿真:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity BCD7 isport(Din1:in std_logic_vector(12 downto 0); -显示13位里程数Din2:in std_logic_vector(12 downto 0); -13位费用clk_scan:in std_logic;SEG:out std_logic_vector(7 downto 0); -数码管显示DIP:out std_logic_vector(7 downto 0); -数码管地址end BCD7;architecture Arch of BCD7 issignal q : std_logic_vector(2 downto 0);signal Dq,Db,Ds,Dg,Dq2,Db2,Ds2,Dg2 : std_logic_vector(3 downto 0);signal data : std_logic_vector(3 downto 0);signal sel : std_logic_vector(2 downto 0);signal Din : std_logic_vector(12 downto 0);signal D2in : std_logic_vector(12 downto 0);signal i : std_logic;beginP1:process(clk_scan)beginif(rising_edge(clk_scan) then q=q+1; end if;end process P1;P2:process(Din1) -进程p2,里程显示variable Din_int:integer range 0 to 9999;variable rb:integer range 0 to 1000;variable rs:integer range 0 to 100;beginDin=Din1;Din_int:=conv_integer(Din); -把din变成整型变量Dq=conv_std_logic_vector(Din_int/1000,4);-里程的千位等于Din_int除以1000取整,并转换成BCDrb:=Din_int rem 1000;-除以1000后的余数存放在rbDb=conv_std_logic_vector(rb/100,4); -rb除以100,转换成BCD存放在Db中rs:=rb rem 100;Ds=conv_std_logic_vector(rs/10,4);Dg=conv_std_logic_vector(rs rem 10,4);end process P2;P3:process(Din2) -进程p3,费用设置variable Din_int2:integer range 0 to 9999;variable rb2:integer range 0 to 1000;variable rs2:integer range 0 to 100;beginD2in=Din2;Din_int2:=conv_integer(D2in);Dq2=conv_std_logic_vector(Din_int2/1000,4);rb2:=Din_int2 rem 1000;Db2=conv_std_logic_vector(rb2/100,4);rs2:=rb2 rem 100;Ds2=conv_std_logic_vector(rs2/10,4);Dg2=conv_std_logic_vector(rs2 rem 10,4);end process P3;P4:process(q) -进程P4,里程与费用的显示beginseldata= Dq;DIP=10000000; idata= Db; DIP=01000000; idata= Ds; DIP=00100000; idata= Dg; DIP=00010000; idata= Dq2; DIP=00001000; idata= Db2; DIP=00000100; idata= Ds2; DIP=00000010; idata= Dg2; DIP=00000001; idata=1111;DIP=00000000; iSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEG=00000000; end case;end if;end process P5;end Arch;仿真波形如图11:图11(2) c47模块的程序及仿真:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity c47 isport(sec,min:in std_logic_vector(6 downto 0);hour:in std_logic_vector(5 downto 0);clk_scan:in std_logic;SEG:out std_logic_vector(7 downto 0);DIP:out std_logic_vector(7 downto 0);hourout:out std_logic);end;architecture one of c47 issignal q:std_logic_vector(2 downto 0);signal dig1,dig2,dig3,dig4:std_logic_vector(3 downto 0);signal dig5,dig6,dig7,dig8:std_logic_vector(3 downto 0);signal data: std_logic_vector(3 downto 0);signal sel:std_logic_vector(2 downto 0);beginP1:process(clk_scan) -进程p1,输入脉冲Beginif(rising_edge(clk_scan) then q=q+1; -上升沿加1end if;end process P1;P2:process(hour,min,sec) -进程P2,时,分,秒的设置 begin dig1=00& hour(5 downto 4); -dia1定义4位,进行定义dig2=hour(3 downto 0);dig3=1111;dig4=0& min(6 downto 4);dig5=min(3 downto 0);dig6=1111;dig7=0& sec(6 downto 4);dig8=sec(3 downto 0);end process P2;P4:process(q) -进程p4,显示时,分,秒beginseldata= dig1;DIPdata= dig2;DIPdata= dig3;DIPdata= dig4;DIPdata= dig5;DIPdata= dig6;DIPdata= dig7;DIPdata= dig8;DIPdata=1111;DIPSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEGSEG=00000000; end case;end if;end process P5;P6:process(hour) -进程p6,在不同时段的设置,来完成不同时段的计费beginif ( hour=100011 or hour=000000 or hour=000001 or hour=000010 or hour=000011 or hour=000100 or hour=000101 or hour=000110 ) then hourout=1;else hourout=0;end if;end process P6; end one;仿真波形如图12:图12(四)点阵显示部分1、 所需模块如下:图132、DM_ROM点阵显示模块作用:将要显示的汉字或字母按照“1”为点亮,“0”为熄灭的规则设计程序,并显示在两个8行8列的点阵显示模块上3、DM_ROM模块的程序及仿真:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity DM_ROM is -实体名DM_ROMport(reset:in std_logi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论