|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;$ ^% O: U" @; {/ C' x
use ieee.std_logic_1164.all;& G0 |5 t' C+ _) c& S3 U. \
use ieee.std_logic_arith.all;- ^) R; c/ F- o( g3 x V
use ieee.std_logic_unsigned.all;( ?8 p' s* ^$ X' H q! V& G
entity hour is) Y7 i$ b9 f( y1 f9 ?. ?/ e- B! K
port(clk_h,clk_t,tp_h,res_h:in std_logic;
l0 h7 _/ W: P# j, X6 e0 x8 o hset:in std_logic;$ m8 H; G, M! f# B% T& Y, }" G% I/ |
sig_h:in std_logic_vector(2 downto 0);, u- L& b* T: D; x
din_h1 ut std_logic_vector(3 downto 0);
+ ? G2 J: w7 x k$ n/ ] din_h0 ut std_logic_vector(3 downto 0);& C- J6 ~; h; ]; p
pm ut std_logic;/ q# ?1 o$ }5 A, r2 j
cp_h:out std_logic);
" z+ y& c0 b: j) X 8 {5 g6 W$ p: e# a8 A! W
end hour;
9 G7 _' z# B4 }% qarchitecture behav of hour is9 Q% |! }4 |* q
signal clk:std_logic;, P0 N, s/ H4 P1 s. K6 b2 I
begin& t9 \9 u, D# {) w" J
process(clk_h,clk_t,tp_h,sig_h,res_h,hset)7 F+ W3 d# h/ z
variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);+ v# c% G# }) [% I+ e( w2 F* v) E
variable co1:std_logic;, @( }) d' m9 Q' `* z0 @3 s
variable co2: std_logic_vector(7 downto 0) ;
m P( v$ o; S; M5 g- E9 R begin ' N. Y4 c! H, m3 z9 G
if sig_h="001"and tp_h='1' then clk<=clk_t;5 t) ~3 y3 g: P# y7 g
else clk<=clk_h;7 L2 j0 C0 h1 u P8 s/ B+ w: H
end if;4 L: x8 g1 k! L
if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');
. i6 }8 S2 N# C, d T, H5 Q elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;5 e1 I( j3 b; N; F
if cq1="1010" then cq2:=cq2+1;cq1:="0000";0 v' `' E; r6 g
end if;
# i/ N) b! j8 s& Q* |) b; i if cq2="0010" and cq1="0100" then
# T! u' k) ^7 ]+ l/ ~: }6 v% B; M cq1:="0000";cq2:="0000";
/ P7 X1 o3 v4 t co1:='1';& N- W' E' Y! \: J* l3 Y& D
else co1:='0';
5 H1 Z: v0 b$ S end if;* y' j# Y" a* Z7 b" T( I4 G
if cq3="1010" then ( |# Q% x+ n4 s6 X8 s3 w* i( s
cq4:=cq4+1;! o' F2 F) b: V3 ]0 z. l, B v
cq3:="0000";
. F% O7 [# x1 Z, n end if;+ J$ `, E/ [; D/ a3 k0 Y& Y; t
if cq4="0001" and cq3="0010" then $ I' u9 x* T. O
cq3:="0000";cq4:="0000";co2:=co2+1;4 }1 U& _* e+ G9 z- X! n7 W
end if;
p2 G3 B# \. M3 n end if;
+ o u- A+ O' P; H( N if hset='1' then
" P1 N5 T( W2 M1 h din_h1<=cq2;din_h0<=cq1;cp_h<=co1;
. [& }6 A/ w/ c- c1 e, I else
8 {$ P! r ?2 b. T if co2(0)='1' then
1 {. k- H. i& o3 V1 u, F v0 y" b% C if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';. m" r% m( Z1 y& w/ T/ s
end if;* u" D: i& L% X- ?; k
pm<='1';
" G, w' K5 t+ m/ @% [ else pm<='0';
) h" f/ s5 c, x4 X) E( h* T end if;
* Y8 z9 k C# h! B8 D! z if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';5 \( V4 K: t8 ?* a
else cp_h<='0';
, s2 m5 S$ w9 @ end if;! x+ i/ R* D+ ^' s* t! s' j
din_h1<=cq4;din_h0<=cq3;
0 Q1 @% v/ F. K7 d. ?0 \; \+ K- J end if; --12/24转换( B! L. f3 `) O9 p( A! T/ R
1 m5 m( p' |: S end process;
* f+ v9 H3 H6 g/ m$ I2 dend behav; |
|