|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;
+ l# s8 ~( a4 y, e" w8 O2 s7 \/ Uuse ieee.std_logic_1164.all;5 r6 M" t. R- s0 [+ W, ?8 ?; m
use ieee.std_logic_arith.all;& s3 `* v' R% U6 e5 G! g, p* ]2 Y7 w0 V
use ieee.std_logic_unsigned.all;0 @6 T2 s6 U, F; d& Y
entity hour is- T2 y$ S3 ]0 r" O1 v
port(clk_h,clk_t,tp_h,res_h:in std_logic;
( M! \! _6 i" ?: @& a& H0 L8 z hset:in std_logic;
1 }" f1 z# S& [6 A sig_h:in std_logic_vector(2 downto 0);1 r( ~1 P7 ~7 E( {, }: G% R
din_h1 ut std_logic_vector(3 downto 0);
3 ^. H, E1 ~3 s0 S din_h0 ut std_logic_vector(3 downto 0);* b3 S2 A" D6 I! Y3 F$ }
pm ut std_logic;
9 b6 {6 w# q2 F. ?0 z4 v4 @% ` cp_h:out std_logic);
3 s, g) ^- B: |) e, X 4 h! \' X) x- b0 o# Z8 g/ d7 {
end hour;, f1 l; D ~5 {& a5 f
architecture behav of hour is/ f* n; P3 Q! D1 N& Y/ Q
signal clk:std_logic;
4 g' T8 Q- P6 M$ Tbegin
) R9 b0 n c# v* C/ @* [ process(clk_h,clk_t,tp_h,sig_h,res_h,hset)
$ ?3 |- V% `; ^: D& k3 l variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);; i; E U3 v8 Q
variable co1:std_logic;
, ^6 K$ G( S6 h" d! h5 r9 t& p( s variable co2: std_logic_vector(7 downto 0) ;% ]5 F* S! s& g; G& E& B! a! D
begin 5 \- ^; [- k/ {( @) f& Q
if sig_h="001"and tp_h='1' then clk<=clk_t;& V! r! z D4 N% W& ~
else clk<=clk_h;6 p% D3 _$ h1 {5 E- h% |
end if;
/ Z* ?: B: q. i( V2 h1 }* D if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');$ ?" Z, S2 ]1 x- E% n
elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;; D- @0 e9 C; w1 r g8 Y7 d1 p% B, X
if cq1="1010" then cq2:=cq2+1;cq1:="0000";. Z& ^/ o! N" w+ M, p1 a
end if;4 r" T6 k' L) G8 T% j3 v
if cq2="0010" and cq1="0100" then
* o( ~+ d+ H1 V" N `9 C! Q; l cq1:="0000";cq2:="0000";! O4 w( R. G [6 |
co1:='1';
[% z R! B5 G. E* w! }8 ]" h% | else co1:='0';- Z" K/ Y$ F8 P+ `8 ?
end if;. a/ F) e' N& V. n2 B, d. d
if cq3="1010" then
) u1 j; m2 O1 l. [7 c cq4:=cq4+1;/ D7 X* _" O+ L. T/ H% j. d5 Q
cq3:="0000";0 X! b" Y$ D! e. B
end if;
8 N( i* {- U' b; J0 v6 J8 A; u if cq4="0001" and cq3="0010" then
2 [, w8 a' @% c+ Y cq3:="0000";cq4:="0000";co2:=co2+1;$ {6 `0 m6 ?3 q, Z5 y0 p
end if;) [, m V; w$ l, Z
end if;# r( J$ J& B G0 Y+ ?( U
if hset='1' then 4 {7 c# M: {& }% i9 p* s( I& h" G! {0 y
din_h1<=cq2;din_h0<=cq1;cp_h<=co1;/ b- G0 d1 y$ \$ A0 \
else
9 m4 H& c8 h5 W. x5 c, c if co2(0)='1' then 9 K8 S' t5 v; N6 V8 K4 A
if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';+ b* h* h7 x8 K% c1 B- \& k" \
end if;
1 A3 I$ B) F7 M' x8 Y$ g; y pm<='1';
. H# E) {& h" ]- y else pm<='0';
+ J8 R( e: P0 f" D- | end if; W6 N6 n+ ?! Z! o% P. @
if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';0 j K' N6 T1 w+ @: W! E
else cp_h<='0';8 j* l6 t4 A! x2 C6 w6 a- ]: S
end if;
4 O: C- z. _) {$ m din_h1<=cq4;din_h0<=cq3;
" O m' k$ z& I4 J5 T end if; --12/24转换% `1 N4 I: E8 d9 B$ A$ h
3 `$ [) {* s; I4 `) z) A end process;3 T( q" U. r. l- ?4 [9 X2 e8 o
end behav; |
|