|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;
: `( I' I2 x9 G1 B$ ~' |9 c& Ause ieee.std_logic_1164.all;
: q3 t; I P' ~8 q* v ]use ieee.std_logic_arith.all;
! o3 [: s' q' o1 ?8 }; K; @; k; @( ~0 ]use ieee.std_logic_unsigned.all;
& z4 k/ N. d' M7 Aentity hour is0 l" t0 z3 m2 l A1 D# i: m
port(clk_h,clk_t,tp_h,res_h:in std_logic;# J+ s( T+ M7 t3 k9 E
hset:in std_logic;' `# ?9 N' ?; F$ j( p$ k3 @' F" Q
sig_h:in std_logic_vector(2 downto 0);
, q$ _* c F$ m7 M din_h1 ut std_logic_vector(3 downto 0);
- A+ q9 X: ? T" E. s7 k( y7 T9 f0 X din_h0 ut std_logic_vector(3 downto 0);* g( h9 \' @! F+ D7 {/ X
pm ut std_logic;
# \3 u( x1 h9 V) Z cp_h:out std_logic);8 l7 H2 ]6 N+ U2 n8 @ E! B$ F
+ U% R% g' Z" ]( |1 `8 V9 h
end hour;7 @; x2 v7 o; |: k/ i
architecture behav of hour is
# S6 ]- c2 l! t. T$ Psignal clk:std_logic;: P+ f% L/ ^1 _' D: K' J
begin4 I' {0 L/ @$ M; ^! k
process(clk_h,clk_t,tp_h,sig_h,res_h,hset)
{4 |7 V. h1 J- U& F- i0 t variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);
/ B' f1 o" ?5 R% o4 d. E8 \; A, x; l variable co1:std_logic;
+ w+ K+ ~$ z9 w4 b variable co2: std_logic_vector(7 downto 0) ;8 r& v" l8 ], t1 o" N- w
begin . A8 s2 H# `% S1 f) [& ~9 {7 K
if sig_h="001"and tp_h='1' then clk<=clk_t;
* N. p9 J% F$ V( @( I% w else clk<=clk_h;
+ b; l5 Z9 E8 P) `* `5 o; d( Y/ ? end if;
8 ~' ~8 Y+ J9 H if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');
$ E6 V n v, f elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;
" R' i0 w$ [: m2 Q2 ` if cq1="1010" then cq2:=cq2+1;cq1:="0000";7 a/ N! z& ]0 w" Y* M3 j2 x
end if;: q6 `; m5 H& k4 O
if cq2="0010" and cq1="0100" then, ~% r- B6 R9 @" [! u
cq1:="0000";cq2:="0000";& p& ?6 l1 w7 }
co1:='1';/ i9 h+ E" f5 ^, P. R7 b& t+ e1 b- r5 P7 K
else co1:='0';. a- } f* ~% [; ^8 F
end if;$ H* Z- i) \8 G3 g
if cq3="1010" then ' h7 u9 y7 R2 A# b; v
cq4:=cq4+1;
. Y7 U% k5 J/ }7 j! [: a4 E cq3:="0000";# i* z; X y' V* j
end if;: U) {. o" n. ?% [
if cq4="0001" and cq3="0010" then
) {' @. g3 }) F3 A! H. L& S cq3:="0000";cq4:="0000";co2:=co2+1;
* L: W2 ~% V3 w% f' R0 z end if;9 \9 v1 S8 B* p i
end if;
+ [3 e: U! t4 ]1 j if hset='1' then
[. Z# Q0 c) g7 a din_h1<=cq2;din_h0<=cq1;cp_h<=co1;
^/ k% J' F) ^7 m5 r/ s3 P else; `& B8 m$ D; k
if co2(0)='1' then
# R7 q# v% i7 w1 q% ?4 }1 F& H; l6 y if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';" J" w: j6 ~% V# M
end if;4 U) ?; L n2 L7 F% @, A& D6 }8 C
pm<='1';
. q( c' E0 S' }3 H) Z* H else pm<='0';
0 }. B8 L+ W7 l' n% u" j' y3 v2 a end if;
( C! n d+ Z9 l% q$ i if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';
: R9 G% V: V$ \3 Z& Z8 L7 y/ s else cp_h<='0';
) i6 J: P7 L! L' z7 c end if;
) Y8 S( ?% j, ` X5 z' H2 q: }2 f din_h1<=cq4;din_h0<=cq3;
8 @5 @) v- R3 D8 S& N0 N8 [5 W4 B end if; --12/24转换8 T1 b! ^1 |; w' Y2 ]% G) v
+ O# {1 S! _2 e- |* w' S! ?) U' X end process;
" N m. ~; J) {8 N% X2 \4 tend behav; |
|