|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;
: W3 x( h& J* \. {+ H0 `* [use ieee.std_logic_1164.all;
7 E& U3 q$ Z& k3 Puse ieee.std_logic_arith.all;
0 h! w2 G' N! z; I) h iuse ieee.std_logic_unsigned.all;
( L, ~9 y( r* ?+ r' Yentity hour is
r$ p. g' g- J1 ^ port(clk_h,clk_t,tp_h,res_h:in std_logic;
& ^0 K. g4 O. s/ P9 F; x } hset:in std_logic;; D ]3 c/ r/ @ g$ P# M
sig_h:in std_logic_vector(2 downto 0);
: I$ ^/ K. ?$ R. `; X din_h1 ut std_logic_vector(3 downto 0);
3 I Z8 t0 f+ p$ G& [$ B' K" I4 p! ^ din_h0 ut std_logic_vector(3 downto 0);) d; H# Z% ^4 b5 ^* c9 [' r
pm ut std_logic;6 }8 M% [/ p$ s {1 c( i
cp_h:out std_logic);
5 E T0 n9 L2 }. V) y 2 B: ^9 z' `& F7 f6 R Y7 \
end hour;- l- E! R% c- o5 w/ ~; m5 y
architecture behav of hour is9 s% [( ^. m, B" B1 \; l
signal clk:std_logic;
$ W/ Q. a3 Z C- |6 s& C' z3 Obegin' f, |4 G( ]& \" n
process(clk_h,clk_t,tp_h,sig_h,res_h,hset)
- H5 \7 F! {' B# ?9 e9 m variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);, V# ?8 M5 f4 k" P% c1 c
variable co1:std_logic;
3 ] S2 g! ?! E variable co2: std_logic_vector(7 downto 0) ;7 x$ L: E7 |% ?5 x; D$ r0 z
begin 7 W: V) V+ ]3 r6 H1 g
if sig_h="001"and tp_h='1' then clk<=clk_t;
! a. S1 g, z L! v else clk<=clk_h;
/ o% M- D; }6 Y- a end if;# I' t1 w) e% ?# t* S. T
if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');
# |; x8 Z2 h5 t+ J0 n7 g elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;
) T0 Y5 y# Q1 C7 _& y: i1 @5 O if cq1="1010" then cq2:=cq2+1;cq1:="0000";
# F$ {( K- F" y+ i end if;
- _) J& {$ W, i if cq2="0010" and cq1="0100" then6 x9 S: f6 k) p3 w, I$ c4 D1 E9 ^
cq1:="0000";cq2:="0000";* h. v8 m; ~+ h5 \. V) Z0 _9 B
co1:='1';! U7 W. f+ ~. c0 D
else co1:='0';
! G% N6 b8 S3 b' r end if;
; w9 l! @; w: w1 {+ E3 N if cq3="1010" then
; S$ c& ^4 N: Q3 e7 H cq4:=cq4+1;
- A# Z0 v( ^: `, @2 Z7 b cq3:="0000";# \9 e! j2 C A4 ]3 h' U
end if;& w7 _8 p: T4 a$ E
if cq4="0001" and cq3="0010" then 6 I% E" `' d; R2 V4 t
cq3:="0000";cq4:="0000";co2:=co2+1;
- f) l( j/ A f9 k, z end if;
. d9 p( {) P0 t1 H/ S end if;( @- Q) @0 v- O0 }: W: y" q7 O
if hset='1' then
5 Y9 g: O- ?, L din_h1<=cq2;din_h0<=cq1;cp_h<=co1;0 A0 L& `7 q+ q; H
else1 P4 U6 W8 R& A @) F
if co2(0)='1' then : ~1 H2 L, S* c) t2 J$ b
if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';7 M; ]9 X: y3 ?5 u
end if;
0 p. x% K- D: w: K pm<='1';
) I0 C' g& y1 T else pm<='0';
+ z k( X# S8 d( E7 b1 Y. ^7 t t end if;
- p4 N a: y2 S& c if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';5 p; r9 s+ R$ f7 | z# c5 K
else cp_h<='0';5 Y; I5 a/ r) F
end if;0 k9 Y6 x. [& ^; C
din_h1<=cq4;din_h0<=cq3;
& }( }: f0 y7 J5 A( |' I end if; --12/24转换
7 d5 C" P; H" I6 p; a
" J& |- Z$ k! Q B0 K; i; K end process;
( |6 d g* B- H+ i3 @end behav; |
|