|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;
4 |( u. \1 G8 m8 B$ nuse ieee.std_logic_1164.all;
+ ^$ x$ W1 r5 m, v2 t$ |3 D/ i2 O( wuse ieee.std_logic_arith.all;0 R) M; ^% r8 X' K$ c
use ieee.std_logic_unsigned.all;0 U( W7 b2 }+ Y, r% z, V+ a0 Z
entity hour is" E) [8 X; \5 U9 y' v
port(clk_h,clk_t,tp_h,res_h:in std_logic;
3 t ]5 b1 u( S6 |$ a. B% F$ A# q' R hset:in std_logic;
/ _' S. W! h3 O, z6 U) Q sig_h:in std_logic_vector(2 downto 0);
* J5 l3 Q. \0 ]2 P5 C din_h1 ut std_logic_vector(3 downto 0);+ s1 \: S+ f( X+ [# E2 l4 A0 [$ g
din_h0 ut std_logic_vector(3 downto 0);
) A9 ]. X3 _/ g& F pm ut std_logic;
, B: K: D: c1 K9 V) O( Q cp_h:out std_logic);4 g, q) O+ Y* n" T2 n
) c% T s; t2 N* J
end hour;
1 ?" o3 V' f8 w8 _+ I, _4 rarchitecture behav of hour is
1 k5 a: @( e/ Q9 P. f, V2 msignal clk:std_logic;
/ g( y- ]- m, s: [# Cbegin0 ~3 u4 K3 m7 g0 j3 `3 u; W
process(clk_h,clk_t,tp_h,sig_h,res_h,hset)
. p% N" t2 h3 O* v5 a$ ^ variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);
5 Y7 ~& l5 {( W1 U6 @ variable co1:std_logic;2 Z- h, O9 N& j; y! R
variable co2: std_logic_vector(7 downto 0) ;
6 C1 v9 \0 g: S& c+ N& I1 x9 S$ S. r begin 4 h5 L8 w- E4 f$ `4 W, |
if sig_h="001"and tp_h='1' then clk<=clk_t;
' m. v% i0 y" c( w% P else clk<=clk_h;4 {5 b8 h+ I* N/ Q
end if;
0 X2 r8 ~; k) r- R. G! L# z5 { if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');
" y1 M8 S; C7 P# R- [; k, E elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;
/ C" s9 t5 Z- \ if cq1="1010" then cq2:=cq2+1;cq1:="0000";
& S. K! q6 X# M' H% x$ o end if;
7 ^8 W! h7 B& |; @& V0 z if cq2="0010" and cq1="0100" then
& [ ? e5 Y, C5 M cq1:="0000";cq2:="0000";
1 O: B7 l# Q" G2 S& R co1:='1';! B! B/ x: o" y
else co1:='0';
! e5 K0 k+ v+ W" d end if;# R1 M( V9 ]$ ?: o/ |0 F( n
if cq3="1010" then 2 `( A h: W, _7 k4 P
cq4:=cq4+1;
+ A2 n0 a+ E# Z9 ~1 |: R5 _) U2 r cq3:="0000";
6 d) o) d: p! c4 Y6 |9 \ end if;
4 N2 C- L. y2 v. {7 J if cq4="0001" and cq3="0010" then 9 a# M" |& T* n c
cq3:="0000";cq4:="0000";co2:=co2+1;' i3 _6 P& |. _, d8 q1 D
end if;
6 `& q6 k4 m* J$ H# D2 T; M' f end if;
7 C h* f3 W; d+ s( a if hset='1' then " g& S* ^/ ^* Q+ X6 P2 l% \6 F( l
din_h1<=cq2;din_h0<=cq1;cp_h<=co1;
3 q* ?( y3 ?0 _" n% B else
" L5 S* m3 x9 p4 d if co2(0)='1' then T2 s; g# w R7 D" Y8 l2 B
if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';
- `6 x" c0 H( c. n3 u9 B& ?2 E$ [- i end if;8 W2 H0 T; m$ L
pm<='1';9 ~' Z( }) I3 _+ G5 {
else pm<='0';& g J5 h8 ?7 C# y6 L
end if;" w; s0 y1 e+ u0 \) _" [6 k
if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';
W/ b) m, ?9 g% p8 O7 l else cp_h<='0'; B; k! \- N% g( ?' j9 c2 I
end if;
9 X% b4 ? Z# X3 B din_h1<=cq4;din_h0<=cq3;
" B: ?5 i9 w6 y b2 n end if; --12/24转换9 W6 H. m1 a) w9 g
( i5 F% |2 v2 D6 ]" P end process;/ X5 K: w4 J9 p6 _. `; j
end behav; |
|