|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;
5 a" D1 q, S! A; s, h: K* }7 xuse ieee.std_logic_1164.all;2 T* S; E/ F; Y: U6 |* q9 j7 ?
use ieee.std_logic_arith.all;2 x3 T1 P; Z3 l8 `
use ieee.std_logic_unsigned.all;2 Q* ?7 i! ^$ Z" X9 R8 A$ {% z' m
entity hour is6 `. ~, R, J# W9 K- y0 B3 I+ y" E8 O
port(clk_h,clk_t,tp_h,res_h:in std_logic;
7 U+ z/ L2 L& b) H# k hset:in std_logic;
9 \; D. c% v: Z8 w, S/ x& y; y" t sig_h:in std_logic_vector(2 downto 0);
0 F2 Q Y2 y' p; `+ ^. u8 |+ S din_h1 ut std_logic_vector(3 downto 0);
+ s; p4 |' w; F. j _, E* V din_h0 ut std_logic_vector(3 downto 0);
/ k; p* G+ l9 c% r$ g' b) L pm ut std_logic;
; \% j7 f9 | f! E3 i) Y cp_h:out std_logic);
3 c* p0 Z( _: x% ?
" f" }" d& Q2 I3 c! ?) hend hour;+ \1 |& d7 ? P. }( F
architecture behav of hour is+ _3 ?- v; g% b" L2 b. h
signal clk:std_logic;1 ~; u% o c- [: ^- k! [2 I# q
begin
1 G/ R3 m3 t2 c& V6 ` process(clk_h,clk_t,tp_h,sig_h,res_h,hset)
7 T6 Z4 K# j. V, } variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);
* O! p% S+ C3 p6 c" [ variable co1:std_logic;4 i7 _$ m4 ^6 ~9 n6 O" J+ Z
variable co2: std_logic_vector(7 downto 0) ; O* ?2 C- [. ?5 a) @& C1 ] F6 W' S0 j
begin
6 ^/ s a4 _, {8 |4 j9 K: G if sig_h="001"and tp_h='1' then clk<=clk_t;! _- Z$ x+ S* n9 |
else clk<=clk_h;
1 c# Z5 r* I, l end if;
; y% C; ~6 A0 j/ ? O) y2 S if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');7 b9 i, [, a) S, B
elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;- J' r& X) ]" w2 O
if cq1="1010" then cq2:=cq2+1;cq1:="0000";$ ^3 y) e6 [" i! h2 A- h+ L% Z! q6 J
end if;
$ N* Q% J6 l) p if cq2="0010" and cq1="0100" then+ t9 p, l4 k2 l/ C% ?
cq1:="0000";cq2:="0000";! j& I. G: M3 [; o) v, u) P" N! s
co1:='1';8 S; A* S j$ {9 U) E, V9 |+ g
else co1:='0';
! E/ i g C+ q- Z2 j6 |/ t% V end if;
" n) w9 x+ U3 A& `- G if cq3="1010" then ' M! q" q4 o D8 j
cq4:=cq4+1;( H" N" G# u! v6 [1 {8 H9 g
cq3:="0000";. `1 F% T z6 p
end if;
; v, A/ V8 m+ `# ]" L4 H if cq4="0001" and cq3="0010" then
* L1 X' R E! |( r+ v+ f& j# n cq3:="0000";cq4:="0000";co2:=co2+1;: N! W5 z: W, I8 \9 i( Q
end if;
& Y: \7 B' L; K" x; c* j9 d end if;
0 T3 g' I8 v! K7 b2 O$ M: j) b if hset='1' then
" k; F( i: G. f8 v _8 Y/ D; \2 Z din_h1<=cq2;din_h0<=cq1;cp_h<=co1;5 X0 ]6 B' w" N. a; ]7 C
else
9 \! q8 b# l6 E" E q if co2(0)='1' then $ n3 J0 A( {; V& |# W! V0 e/ @7 `! Z
if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';# U4 q$ z- z4 H# ` ~+ _
end if;$ f( a# ]1 W) b: v) n
pm<='1';& w( S, W7 _! r0 M( S [
else pm<='0';# M! R3 Z) ]. M& D/ A% O
end if;
2 a& r g% @9 S1 i' k6 [9 a! ~& s if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';% ~+ V, V& K1 }4 ~" N- d
else cp_h<='0';7 g. B$ ?. ~* a+ I
end if;
3 x8 E: o+ F* j( M0 d8 q7 `3 f" w din_h1<=cq4;din_h0<=cq3; % i: i h: }9 j1 x3 P9 e9 m4 U
end if; --12/24转换, `3 W8 V# I8 R* ] k
q( Q6 }4 ?$ k/ _% q L
end process;6 d6 z8 Y( h2 p" \
end behav; |
|