|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;( ?+ c# A1 ?, o+ Z/ e1 Z$ y; C
use ieee.std_logic_1164.all;
, V# v' m4 ^! k8 O3 O% I8 C2 I3 |- m+ nuse ieee.std_logic_arith.all;
5 S& @3 x( L3 o `use ieee.std_logic_unsigned.all;, y5 o I: t5 \! z& a( M4 N& ^
entity hour is+ ?( W, t: R5 ~" Y' h
port(clk_h,clk_t,tp_h,res_h:in std_logic;+ E+ p3 U: {' G. W+ `
hset:in std_logic;
! o& [% G6 B$ T( R* e sig_h:in std_logic_vector(2 downto 0);9 U+ u' ~2 p4 f# H( E) l
din_h1 ut std_logic_vector(3 downto 0);- c3 k. L" z% q9 ]" w
din_h0 ut std_logic_vector(3 downto 0);
0 {% k( R; n: j& L L pm ut std_logic;7 a0 v; L4 w' P1 u. Q: U! Y
cp_h:out std_logic);/ v; T7 u) x% \( c6 l
# `: j$ A. I# D6 |; k
end hour;
* g3 n% c" K0 K7 b( v8 varchitecture behav of hour is
# H1 j: h& D! [9 |1 r3 B4 ?1 ]signal clk:std_logic;$ H w/ I4 R( Q' b' a7 W3 {
begin
3 O s% b, ^" B. a/ N process(clk_h,clk_t,tp_h,sig_h,res_h,hset)4 I. D& T6 B1 V+ M- v2 I; ~4 u
variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);$ i6 ^! B: t }2 V( @
variable co1:std_logic;6 A# G7 q9 I+ D% e8 ]% V* P
variable co2: std_logic_vector(7 downto 0) ;% }3 R: D5 J" H5 {5 V2 `$ w: q! U
begin 1 u0 f2 R% Z$ G* `4 m
if sig_h="001"and tp_h='1' then clk<=clk_t;
* i3 }& T* v* i6 ? else clk<=clk_h;
; g7 B" ^3 p- o5 M# ` end if;
5 R2 Y/ m& s, p t% x$ J) @ if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');! m1 ~0 W* v: }, j+ g+ w
elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;$ e) |* N) B8 N: T9 W
if cq1="1010" then cq2:=cq2+1;cq1:="0000";2 r6 j# D0 b$ k
end if;
) h' \3 @. J& u& K if cq2="0010" and cq1="0100" then
, Y7 F$ F- b0 e3 j cq1:="0000";cq2:="0000";; d: w+ {+ f2 i3 ^
co1:='1';4 o# h" w# d q$ H' o
else co1:='0';% y1 x' S" i* k) q1 `7 c3 ~
end if;
7 N# S+ N4 f4 `& j if cq3="1010" then
! k+ h' ~1 B. {$ O% N" N0 Y4 X8 O/ A cq4:=cq4+1;
T. {% V6 a6 F f cq3:="0000";0 ~( M* s: n2 s+ F
end if;
0 e4 l( ]; Q: a, O$ R0 t' j if cq4="0001" and cq3="0010" then 2 U% A$ C6 u+ w) Z! X8 A
cq3:="0000";cq4:="0000";co2:=co2+1;0 T# j, [# |5 t7 K
end if;: Q! ^( r; a8 c! J, E4 v
end if;
+ N$ y: k8 w. g0 z/ s3 m. V* A if hset='1' then . c, f9 J; P. Y7 {2 X1 v! h6 v
din_h1<=cq2;din_h0<=cq1;cp_h<=co1;2 S% x8 R( Q( {& v0 K2 Z7 Y
else
% ?% B) {; o: f( R- P: V if co2(0)='1' then 1 J, x$ p1 z/ P: _1 }8 g6 \
if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';
. H7 ]; Z7 t7 y/ L+ d1 C% m& T end if;- N9 |+ Y2 E' C, I/ j8 U6 V% R
pm<='1';8 k9 ^3 E! ~- k- ^& v; {
else pm<='0';
( O6 {1 \: k0 [' ^. l& \ end if;/ p+ Q4 o" ~; ?- ]# A: S( b; e' ^3 Z
if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1'; Y% r" f: h7 T) G
else cp_h<='0';
) w: e; v3 H5 M2 |/ O5 Z% S- z end if;. }. G+ p o& r& u5 L6 }/ w- b
din_h1<=cq4;din_h0<=cq3;
. r+ C/ e5 B, f, _! j% q' \* _ end if; --12/24转换- g' ^2 f$ m+ S/ Z3 g" j3 o1 M' [
# w' I# ]+ b: j, i, y end process;
3 q0 L9 o: F9 I, L+ M' mend behav; |
|