出租车计费器VHDL语言Word文件下载.docx
- 文档编号:16445097
- 上传时间:2022-11-23
- 格式:DOCX
- 页数:12
- 大小:88.90KB
出租车计费器VHDL语言Word文件下载.docx
《出租车计费器VHDL语言Word文件下载.docx》由会员分享,可在线阅读,更多相关《出租车计费器VHDL语言Word文件下载.docx(12页珍藏版)》请在冰豆网上搜索。
outstd_logic);
endTaxi_part1;
architecturebehaviorofTaxi_part1is
begin
process(clk,reset,stop,start,sp)
typestate_typeis(s0,s1);
variables_state:
state_type;
variablecnt:
integerrange0to1400;
variablekinside:
casespis
when"
000"
=>
kinside:
=0;
001"
=1400;
010"
=1200;
011"
=1000;
100"
=800;
101"
=600;
110"
=400;
111"
=200;
endcase;
if(reset='
1'
)thens_state:
=s0;
elsif(clk'
eventandclk='
)then
cases_stateis
whens0=>
cnt:
clkout<
='
0'
;
if(start='
=s1;
elses_state:
endif;
whens1=>
clkout<
if(stop='
--相当于无客户上车
elsif(sp="
---有客户上车,但车速位0,即客户刚上车还未起步
elsif(cnt=kinside)thencnt:
s_state:
elsecnt:
=cnt+1;
endprocess;
endbehavior;
2.计程模块:
由于一个clkout信号代表行进100m,故通过对clkout计数,可以获得共行进的距离kmcount。
entityTaxi_part2is
port(clkout,reset:
kmcnt1:
outstd_logic_vector(3downto0);
kmcnt2:
kmcnt3:
outstd_logic_vector(3downto0));
endTaxi_part2;
architecturebehaviorofTaxi_part2is
process(clkout,reset)
variablekm_reg:
std_logic_vector(11downto0);
)thenkm_reg:
="
000000000000"
elsif(clkout'
eventandclkout='
)then--km_reg(3downto0)对应里程十分位
if(km_reg(3downto0)="
1001"
)then
km_reg:
=km_reg+"
0111"
--十分位向个位的进位处理
elsekm_reg(3downto0):
=km_reg(3downto0)+"
0001"
if(km_reg(7downto4)="
1010"
01100000"
--个位向十位的进位处理
endif;
kmcnt1<
=km_reg(3downto0);
kmcnt2<
=km_reg(7downto4);
kmcnt3<
=km_reg(11downto8);
endprocess;
3.计时模块:
在汽车启动时,当遇到顾客等人时,出租车采用计时收费的方式。
通过对速度信号sp的判断决定是否开始记录时间。
当stop=1时,不计费,当stop=0,sp=0时,开始按时间计费,当时间达到足够长时则产生Timecount脉冲,并重新计时。
一个Timecount脉冲相当于等待的时间达到了时间计费的长度。
使用1kHz的系统时钟,计算20s计数值为20000。
entityTaxi_part3is
sp:
timecount:
endTaxi_part3;
architecturebehaviorofTaxi_part3is
process(reset,clk,sp,stop,start)
typestate_typeis(t0,t1,t2);
variablet_state:
variablewaittime:
integerrange0to1000;
begin
)thent_state:
=t0;
caset_stateis
whent0=>
waittime:
timecount<
=t1;
elset_state:
whent1=>
if(sp="
=t2;
elsewaittime:
t_state:
whent2=>
=waittime+1;
timecount<
if(waittime=1000)then
--20s,即1000个clk,产生一个时间计费脉冲
elsif(stop='
elsetimecount<
4.计费模块:
计费模块由两个线程组成。
其中一个进程根据条件对Enable和Price赋值:
当记录的距离达到3千米后Enable变为1,开始进行每千米收费,当总费用大于40元后,则单价Price由原来的2元/千米变为4元/千米;
第二个进程在每个时钟周期判断Timecount和Clkcount的值。
当其为1时,则在总费用上加上相应的费用。
entityTaxi_part4is
port(clk,reset,timecount,clkout:
instd_logic_vector(3downto0);
count1:
count2:
count3:
endTaxi_part4;
architecturebehaviorofTaxi_part4is
signalcash:
signalPrice:
std_logic_vector(3downto0);
signalEnable:
std_logic;
process(cash,kmcnt2)
if(cash>
000001000000"
)thenprice<
0100"
elsePrice<
0010"
if((kmcnt2>
0011"
)or(kmcnt3>
))thenEnable<
elseEnable<
kmmoney2:
process(reset,clkout,clk,Enable,Price,kmcnt2)
variablereg2:
variableclkout_cnt:
integerrange0to10;
)thencash<
000000000111"
--起步费用设为7元
if(timecount='
)then--判断是否需要时间计费,每20s加一元
reg2:
=cash;
if(reg2(3downto0)+"
>
"
reg2(7downto0):
=reg2(7downto0)+"
00000111"
if(reg2(7downto4)>
cash<
=reg2+"
000001100000"
elsecash<
=reg2;
elsif(clkout='
andEnable='
)then--里程计费
if(clkout_cnt=9)then
clkout_cnt:
if("
0000"
&
reg2(3downto0)+price(3downto0)>
00001001"
00000110"
+price;
cash<
=reg2+price;
elseclkout_cnt:
=clkout_cnt+1;
count1<
=cash(3downto0);
--总费用的个位
count2<
=cash(7downto4);
--总费用的十位
count3<
=cash(11downto8);
--总费用的百位
5.显示模块:
时间的显示需要用到全部8个数码管,由于实验板上的所有数码管均对应同一组7段码,因此,需要采用动态扫描的方式实现时间显示。
entitydisplayis
port(clk:
kmcount1:
kmcount2:
kmcount3:
clkout:
outstd_logic_vector(6downto0);
sel:
bufferstd_logic_vector(2downto0));
enddisplay;
architecturedtsmofdisplayis
signalkey:
process(clk)
variabledount:
std_logic_vector(2downto0):
ifrising_edge(clk)then
ifdount="
then
dount:
else
=dount+1;
sel<
=dount;
process(sel)
caseselis
key<
=kmcount3(3downto0);
=kmcount2(3downto0);
=kmcount1(3downto0);
1011"
=count3(3downto0);
=count2(3downto0);
=count1(3downto0);
whenothers=>
null;
process(key)
casekeyis
0111111"
0000110"
1011011"
1001111"
1100110"
0101"
1101101"
0110"
1111101"
0000111"
1000"
1111111"
1101111"
1000000"
enddtsm;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 出租车 计费 VHDL 语言