|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;) D! R# }4 q6 M% \! p
use ieee.std_logic_1164.all;/ u& ]. G0 b* K; W! C y2 _
use ieee.std_logic_arith.all;
( |) m( N. ]( D% F7 C, o Fuse ieee.std_logic_unsigned.all;
) E8 d0 t. s( N2 Dentity hour is4 b: s0 F" T, R7 C5 r5 I
port(clk_h,clk_t,tp_h,res_h:in std_logic;2 F X7 s& s- ^
hset:in std_logic;
& ?( P& G! A; `7 n6 e" b sig_h:in std_logic_vector(2 downto 0);! x! V2 `/ j/ X, O( r+ [4 u
din_h1 ut std_logic_vector(3 downto 0);0 Y0 f* f% X; s5 y6 T! _
din_h0 ut std_logic_vector(3 downto 0);) R% o; b* U5 i# Z& D
pm ut std_logic;9 P4 s1 X! W( D2 F$ u$ K& m+ ?
cp_h:out std_logic);7 P5 Q% O# ~3 L B3 Z
: t' X8 }# F6 K" a% Bend hour;
$ {9 x$ D Y! ~9 [9 [1 z B" rarchitecture behav of hour is2 y$ n% A. S0 w( l! I
signal clk:std_logic;' x. v$ g7 h5 T( K, I3 y
begin# _$ l4 t, g7 D( t" ^
process(clk_h,clk_t,tp_h,sig_h,res_h,hset)
7 q& |/ O2 C9 V3 G5 w9 ` variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);* i7 p3 Y$ z) a9 ?( n
variable co1:std_logic;
$ a6 E) g1 c5 A, q8 E% Q variable co2: std_logic_vector(7 downto 0) ;
0 W, R4 ]# J o) I begin 8 s" A! y) S5 k
if sig_h="001"and tp_h='1' then clk<=clk_t;
8 [% J* |2 t. K+ s. D else clk<=clk_h;5 Z% G% W9 B( A( L4 V( k
end if;
* t. j/ W) V/ x" T: H, V4 B if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');
+ C8 }6 H5 B3 ]2 y8 x elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;
+ x5 z4 L3 R$ j, h& c; k4 \ if cq1="1010" then cq2:=cq2+1;cq1:="0000";/ R2 N7 S- v4 F1 G" a. C- `
end if;. u2 T! d7 E' o3 Z! R% y" x1 e
if cq2="0010" and cq1="0100" then7 O6 ~6 ~: s6 ~
cq1:="0000";cq2:="0000";# d; S( [4 }$ @( h! g
co1:='1';, o* {' v; i- @1 `9 T
else co1:='0';
! H. s/ p* C# Z end if;
1 _* m/ P1 \; q1 f% D8 ? if cq3="1010" then " |- p! @0 u6 F6 k* Q
cq4:=cq4+1;, \, H8 x1 H+ `4 F
cq3:="0000";
4 o& [) ?6 n1 Z7 K) z5 ] end if;- p3 e6 A0 t. A/ n
if cq4="0001" and cq3="0010" then
0 u! g i# z3 g5 i. D cq3:="0000";cq4:="0000";co2:=co2+1;
' R a/ l+ Q7 t end if;
+ L; a3 n" i9 a) R end if;. j# Z* v4 f w" i9 v
if hset='1' then : \4 r! i M9 r6 Z
din_h1<=cq2;din_h0<=cq1;cp_h<=co1;. S' z! u% P* ^$ }, Y% `
else b6 S0 b* u0 z+ f8 k
if co2(0)='1' then
% X8 C! D, s" ~, v3 _) e! J4 A if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';
y$ l0 Y9 W; y' U end if;
% d1 `! p3 F+ c pm<='1';% n% E9 _' Y2 `' _ {& H; d$ j
else pm<='0';3 X2 g' K8 x# ?; o
end if;
/ z- G8 k& _ y1 l" Z0 n$ Z3 J) C if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';
) w4 ?" F6 ` ]0 N7 Q. o$ L else cp_h<='0';
8 X/ Z3 a- V- K. t end if;
. q+ M- G# _4 D v2 Y& E/ z6 A p din_h1<=cq4;din_h0<=cq3; & S, c1 `- q: h# o4 D" \
end if; --12/24转换
$ T/ w( e9 R* m; `2 t Z- t) L9 k) Z( I( O" L% o
end process;, {7 h; Z+ T( a( h( U
end behav; |
|