|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;
& B/ b9 K; u2 I3 Q. ouse ieee.std_logic_1164.all;
( {* N; z. e8 b( U5 ~5 E+ u" ouse ieee.std_logic_arith.all;& p) e1 A! o4 B* K
use ieee.std_logic_unsigned.all;
5 _2 U/ Q \8 D) k7 b% a( nentity hour is
7 S, N6 Y& c9 a- M port(clk_h,clk_t,tp_h,res_h:in std_logic; c1 m0 I! E8 p2 T
hset:in std_logic;" J' _! ~1 P& \7 E+ S$ n
sig_h:in std_logic_vector(2 downto 0);, g, q1 N& `" i' W9 i2 n
din_h1 ut std_logic_vector(3 downto 0);; J3 q9 q6 u" o; O
din_h0 ut std_logic_vector(3 downto 0);
" @8 f3 h+ Z# N! S: y pm ut std_logic;
* f* q6 ~/ J* G; n cp_h:out std_logic);
/ a/ ^2 ]. `0 g( M% _% s
9 `* a7 Z3 e2 n0 z$ v# kend hour;
2 ~& D4 R2 h6 M M' r" C7 x. ~architecture behav of hour is1 w) k- B' [5 @0 `+ A" H8 z
signal clk:std_logic;
9 X/ I h1 b$ d; lbegin
- K7 w& k. Z& ~ J t4 n. w7 F/ U process(clk_h,clk_t,tp_h,sig_h,res_h,hset)2 I* J1 }5 t- X) M0 E5 |! e5 Y$ a, L7 S
variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);
- s, F7 ]1 j' D9 C variable co1:std_logic;
7 u. k$ J8 }- ^9 ? variable co2: std_logic_vector(7 downto 0) ;
: ^" t H/ U8 [( [4 h begin / a$ I& Z; m$ b
if sig_h="001"and tp_h='1' then clk<=clk_t;! ^6 f$ M1 {: N5 O
else clk<=clk_h;) f# g7 w4 v9 B: x3 z0 K% H) a
end if;8 N8 F" Q' s2 y
if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');5 j6 F" k% a' R& R
elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;4 `3 x' H# z0 \0 S7 g" X
if cq1="1010" then cq2:=cq2+1;cq1:="0000";' q& p) K% x8 ~
end if;! j) z1 F( Y- ` u8 \
if cq2="0010" and cq1="0100" then
6 ^4 A8 P( s* r& I cq1:="0000";cq2:="0000";
% L7 W' a' R6 X6 D: z- a co1:='1';
8 ]0 k% r" X) O1 G, Q7 ? else co1:='0';- A. z _) Y8 N0 B5 L
end if;3 q/ N3 K$ \' p( x# J b8 {
if cq3="1010" then 2 i5 |! E* z8 M
cq4:=cq4+1;
; x. I# O& S3 J# o6 f. i' @3 { cq3:="0000";
) m; |+ s; b6 p/ a5 G$ ` end if;
6 w, ^4 R' z% r) e& T4 k+ Z$ I) a6 Y2 | if cq4="0001" and cq3="0010" then ! ]% z9 W( Z# q$ C4 I' L) I; j
cq3:="0000";cq4:="0000";co2:=co2+1;
" j3 a& g8 y2 m n end if;
0 M* x. _: f5 g! ?8 ? end if;
5 Y s1 h& y+ L4 u if hset='1' then 0 J8 {/ X4 {- H% M1 V& ?5 F
din_h1<=cq2;din_h0<=cq1;cp_h<=co1;
6 E4 g, X! c8 G/ L3 z7 t2 d( c I" d else
, O; s* P! J7 n4 i& \ if co2(0)='1' then 0 o' S, J' O! u
if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';
' T- e3 [! E. C K- ?# _( ] end if;
0 S( U$ \6 _- c# }- X3 B pm<='1';
# m6 i8 X% X8 X$ [3 A else pm<='0';
- A5 J0 N9 {$ z8 \& x# Q end if;
: W1 R& b# C" S0 U8 ~; T if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';
/ b# ~: F: U: R! v$ s else cp_h<='0';
: Z0 M# L1 _. _, F8 ` end if;2 l$ _8 z+ \3 \# a, D+ L+ v; O
din_h1<=cq4;din_h0<=cq3;
! _0 [5 W, W" ~ K- l end if; --12/24转换! f, W B3 _ d. y. M, r$ o$ k& k
; K) K' k# E: _6 J end process;8 W& `2 [; W. l* Q' G
end behav; |
|