EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
我做的是出租车计费系统,VHDL语言做的,也就是从网上下载的。请问一下下面的程序中SE模块和DI模块是干什么用的啊?拜托帮忙,快答辩了!3.3.1
) G2 @( C- S, u% `: @$ _模块# g( ]; d/ u4 @$ Y' F7 f
JIFEI
+ L; ^, X" v' f& k: V% R的实现
) c' p' q9 `$ M `该模块是模拟汽车启动,停止,暂停加速。模块如图4: CLKSTART
8 S$ A" h! X Y* p2 E8 xCHEFEI[12...0]STOP
4 M# Y: c7 v. K7 k: y* vLUC[12...0]PAUSEJS* W3 {1 M# G: h2 z- z
| % [* Y5 w* s6 s. L4 Z, g3 S- [
图 4
3 k* \- I1 M2 n8 Z" JJIFEI模 块 输入端口# X; Y9 O& Q5 m/ d
START、STOP、PAUSE、JS$ s$ v7 y0 A! G% [, ~
分别为汽车起动、停止、暂停、加速按键。程序如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity jifei is port (clk,start,stop,pause,js:in std_logic; chefei,lucut integer range 0 to 8000); end jifei; architecture rtl of jifei is begin process(clk,start,stop,pause,js) variable a,b:std_logic; variable aa:integer range 0 to 100; variable chf,lc:integer range 0 to 8000; variable num:integer range 0 to 9; begin if(clk'event and clk='1')then if(stop='0')then chf:=0; num:=0; b:='1'; aa:=0; lc:=0; elsif(start='0')then b:='0'; chf:=700; lc:=0; elsif(start='1' and js='1'and pause='1')then if(b='0')then num:=num+1; end if; if(num=9)then lc:=lc+5; num:=0; aa:=aa+5; end if; elsif(start='1'and js='0'and pause='1')then lc:=lc+1; aa:=aa+1; end if; if(aa>=100)then a:='1'; aa:=0; else a:='0'; end if; if(lc<300)then null; elsif(chf<2000 and a='1')then chf:=chf+220; elsif(chf>=2000 and a='1')then chf:=chf+330; end if; end if; chefei<=chf; luc<=lc; end process; end rtl; 3.3.2& F7 e9 I S$ N$ c# ]
模块$ t, b/ L5 s! l, L4 h6 F9 Y1 @4 T4 {
X* I# Y: P- ^$ m' k
的实现' c( I7 J+ I" w+ @4 u5 @6 T( [
模块X见图5。该模块把车费和路程转化为4位十进制数,daclk的频率要比 clk快得多。 AGE[3...0] ASH[3...0]DACLK/ ^: J2 i+ c9 V7 {: O& x
ABAI[3...0]ASCORE
/ Y! s6 E1 X$ pAQIAN[3...0]BSCORE
3 H3 ]) V: A2 hBGE[3...0BSHI[3...0]BBAI[3...0]BQIAN[3...0]! B% S$ R- d; ^. e3 m9 u3 U
| 8 k5 v4 q% ?/ }1 ]
图5 X模块 该模块的程序如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity x is port(daclk:in std_logic; ascore,bscore:in integer range 0 to 8000; age,ashi,abai,aqian,bge,bshi,bbai,bqianut std_logic_vector(3 downto 0)); end x ; architecture rtl of x is begin process(daclk,ascore) variable comb1:integer range 0 to 8000; variable comb1a,comb1b,comb1c,comb1d:std_logic_vector(3 downto 0); begin if(daclk'event and daclk='1')then if(comb1<ascore)then if(comb1a=9 and comb1b=9 and comb1c=9)then comb1a:="0000"; comb1b:="0000"; comb1c:="0000"; comb1d:=comb1d+1; comb1:=comb1+1; elsif(comb1a=9 and comb1b=9)then comb1a:="0000"; comb1b:="0000"; comb1:=comb1+1; comb1c:=comb1c+1; elsif(comb1a=9)then comb1a:="0000"; comb1b:= comb1b+1; comb1:= comb1+1; else comb1a:= comb1a+1; comb1:= comb1+1; end if; else ashi<= comb1b; age<= comb1a; abai<= comb1c; aqian<= comb1d; comb1:=0; comb1a:="0000"; comb1b:="0000"; comb1c:="0000"; comb1d:="0000"; end if; end if; end process; process(daclk,bscore) variable comb2:integer range 0 to 8000; variable comb2a,comb2b, comb2c,comb2d:std_logic_vector(3 downto 0); begin if(daclk'event and daclk='1')then if(comb2<bscore)then if(comb2a=9 and comb2b=9 and comb2c=9)then comb2a:="0000"; comb2b:="0000"; comb2c:="0000"; comb2d:=comb2d+1; comb2:=comb2+1; elsif(comb2a=9 and comb2b=9)then comb2a:="0000"; comb2b:="0000"; comb2:= comb2+1; comb2c:= comb2c+1; elsif(comb2a=9)then comb2a:="0000"; comb2b:=comb2b+1; comb2:=comb2+1; else comb2a:= comb2a+1; comb2:= comb2+1; end if; else bshi<=comb2b; bge<=comb2a; bbai<=comb2c; bqian<=comb2d; comb2:=0; comb2a:="0000"; comb2b:="0000"; comb2c:="0000"; comb2d:="0000"; end if; end if; end process; end rtl; 3.3.3
6 ~* @: _' K' {3 f模块. F; Y/ u* V; I( a& M O
XXX19 o V- }+ w' l8 ^9 v
实现
0 q: _) Y" R8 p- F6 i3 {" ?: E模块XXX1见图6。经过该八进制模块将车费和路程显示出来。该设计采用的是共阴极七段数码管,根据16进制和七段显示段码表对应关系,用VHDL的CASE语句可方便的实现他们的译码。 动态扫描时利用人眼的视觉暂留原理,只要扫描频率不小于34HZ,人眼就感觉不到显示器的闪烁。本系统24HZ的扫描脉冲由相对应的外围电路提供。动态扫描电路设计的关键在于位选信号要与显示的数据在时序上一一对应,因此电路中必须提供同步脉冲信号。 C[2...0]A1[3...0]A2[3...0] A3[3...0]' D$ c# L# i! A$ L4 Q* i
2 u9 m! T" g0 H* R4 DDPA4[3...0]B1[3...0]" O, O& r; L$ f; A2 ^& |
. b* Y: l1 k- A+ P |0 i
D[3...0]B2[3...0]B3[3...0]B4[3...0]3 F) F, f" ?' l5 X5 \8 p6 q
| 7 \1 n" a! ~+ d/ w8 C& s' p& S& G
图 6 模块XXX1 这里采用八位计数器提供同步脉冲,VHDL语言如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity XXX1 is port(c:in std_logic_vector(2 downto 0); dput std_logic; a1,a2,a3,a4,b1,b2,b3,b4:in std_logic_vector(3 downto 0); d:out std_logic_vector(3 downto 0)); end XXX1; architecture rtl of xxx1 is begin process(c,a1,a2,a3,a4,b1,b2,b3,b4) variable comb:std_logic_vector(2 downto 0); begin comb:=c; case comb is when”000”=>d<=a1; dp<=’0’; when”001”=>d<=a2; dp<=’0’; when”010”=>d<=a3; dp<=’1’; when”011”=>d<=a4; dp<=’0’ ;* ~. S8 d0 m! s' n' m! M2 I/ A
when”100”=>d<=b1; dp<=’0’; when”101”=>d<=b2; dp<=’0’;
5 Z0 d( G6 G& ?0 q$ b7 V- qwhen”110”=>d<=b3;
dp<=’1’; when”111”=>d<=b4; dp<=’0’; when3 }8 |6 ?3 O2 b$ h7 ^6 `% W
others=>null; end: {! u5 X7 q4 P) m# W1 z s4 d
case; end# k# x( l* f% z+ M; ?" x
process; end( V( e: ]2 V2 Q) L
rtl; 3.3.4 r0 s1 j; y) |, Z, z4 n1 P
模块; S) E/ Y6 {1 c+ v
SE
e0 ^+ P. Y$ z) Y. H的实现7 T4 i7 S( V0 k
模块6 o$ G5 F6 y7 l" U% `+ x B0 v
SE; M& E/ V% F& } N3 Y8 H1 C3 \! G: i
见图
1 I, A. [8 x9 W" I: O7:该模块是系统检测模块。 CLK9 o$ V7 Q) t" f9 v3 M
# u0 P: u, [5 h3 w$ R
A[2...0]. c- a5 K% O1 w
|
# Y/ _4 |/ `2 M" C图
) V% l+ G6 R& Q* r4 J7 0 L/ h6 j5 V; i& U+ A
SE模1 j, U: F7 o* R; ]( J3 v4 [! A
块 模块SE程序如下: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity se is port(clk:in std_logic; a:out std_logic_vector(2 downto 0)); end se; architecture rtl of se is begin process(clk) variable b:std_logic_vector(2 downto 0); begin if(clk’event and clk=’1’)then if(b=”111”)then b:=”000”; else b:=b+1; end if; end if; a<=b; end process; end rtl; 3.3.5: x- c/ z/ E3 I
模块( U, U+ o0 X7 D$ V; L) e3 e# @+ i" W' L
DI
( N' z& q! O0 n( V+ b- ~的实现
9 o' [2 x x- q, k- L0 c% _) H* ~模块DI见图 8 D[3..0]$ S1 h2 D/ p! b3 W, C6 ?1 i: S
2 @* r: W' d! s2 E f) w7 y7 `
Q[6..0]: m" G2 O$ j) n' `5 Y# O0 {9 a; X
|
1 ], d3 t* X9 M, `1 X9 w& G$ |
, v! v- C2 w( h; r
" V6 I1 x. G+ j+ `& q) ~8 R. `8 K, w) i8 V6 B: j
图8 DI模块
模块DI的程序如下
3 A0 b7 N [* t- o/ X+ l: d library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity di is port(d:in std_logic_vector(3 downto 0); q:out std_logic_vector(6 downto 0)); end di; architecture; C1 ^/ x' ~ ^' H1 d7 S
rtl of di is begin process(d) begin case d is when”0000”=>q<=”0111111”; when”0001”=>q<=”0000110”; when”0010”=>q<=”1011011”; when”0011”=>q<=”1001111”; when”0100”=>q<=”1100110”; when”0101”=>q<=”1101101”; when”0110”=>q<=”1111101”; when”0111”=>q<=”0100111”; when”1000”=>q<=”1101111”; when others=>q<=”1101111”; end case; end process; end rtl; |