|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;( D0 I" w+ X& x# L! s
use ieee.std_logic_1164.all;: `$ i# [2 W ~9 x: k! G& w
use ieee.std_logic_arith.all;
% l' | [6 N+ e6 R0 O9 vuse ieee.std_logic_unsigned.all;
9 P# _/ L# e" ientity hour is- F# a( p' A4 f
port(clk_h,clk_t,tp_h,res_h:in std_logic;
% I0 f0 j* }0 l2 [* X hset:in std_logic;
! r* A2 W* e3 ~! _ sig_h:in std_logic_vector(2 downto 0);. c+ T+ W; G2 l+ ?& X" O0 Y$ T) R
din_h1 ut std_logic_vector(3 downto 0);
. J' t) [1 R, R' A, `0 {- b din_h0 ut std_logic_vector(3 downto 0);5 t9 Q0 a, E, ^2 m
pm ut std_logic;
: N- c% B6 B; P3 y# [( L" L cp_h:out std_logic);8 }! A9 F3 E4 w$ |
: |; v7 Z; j0 B, C# kend hour;: j ~+ ]& V/ i ~9 y
architecture behav of hour is& ^( J6 I5 ~5 n% ?+ K, T; h" j
signal clk:std_logic;- z: a" |+ w; F. m [' ]
begin
8 J+ `6 T( R e$ c process(clk_h,clk_t,tp_h,sig_h,res_h,hset)4 G- @: _1 Q" r9 p3 ?9 Y0 |
variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);3 d0 v& U: e* k0 M
variable co1:std_logic; v0 D1 O& v; }- p0 W/ \. I
variable co2: std_logic_vector(7 downto 0) ;
4 p$ |4 Q) c% Q8 s$ R0 I/ ]# m begin
4 M9 B& ^' U3 \ h6 c if sig_h="001"and tp_h='1' then clk<=clk_t;
( q4 t1 ^: n$ Q( [ J) E else clk<=clk_h;; Q3 u% [9 |) A4 U8 m( m7 I' _0 h
end if;; D* Y# p/ U _
if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');
+ S* R4 y" }( f elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;; B `0 r! I+ p0 K9 J0 I8 O/ W& [
if cq1="1010" then cq2:=cq2+1;cq1:="0000";9 C* f J5 g5 U& O% g
end if;; y2 w6 S; t1 i4 D% _4 F+ k
if cq2="0010" and cq1="0100" then. E- \5 i; m+ L) @, D; p4 N2 e. o! G
cq1:="0000";cq2:="0000";
# s! @0 l2 H! r/ J6 I co1:='1';4 V7 M$ D* h2 i
else co1:='0';
: T+ Z$ T) B' @* [ end if;( l0 p1 L# A2 _/ i/ ?6 P! Q
if cq3="1010" then
& m7 r0 i: i5 `* V; y& L cq4:=cq4+1;1 ]& q: t# W! B4 J
cq3:="0000";
( s$ w' e, w7 e% ]9 d- f end if;
5 t& }/ N' ?4 T8 t' Q! E: ]2 P if cq4="0001" and cq3="0010" then 0 J X6 C0 r. R3 D" r
cq3:="0000";cq4:="0000";co2:=co2+1;* R4 x. a' P$ h
end if;
3 l* [! e8 ?9 N" y end if;
?3 c* p0 s' S. \ if hset='1' then ' P# J; E) w$ t' l# l, G
din_h1<=cq2;din_h0<=cq1;cp_h<=co1;
$ y `3 d: u4 E" R2 T! A0 f3 ? D else
4 G, R. D& b, h& F if co2(0)='1' then + H& u* d, Z/ U* @9 l
if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';
2 \1 j; l: t4 m1 a end if;
5 _# ~' \) \% z1 A6 Y- A pm<='1';
7 Q; J+ `# p# g; d, n V else pm<='0';8 p; n7 S& n- ?
end if;1 b6 E7 \' y+ H( x! B8 P
if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';
3 X# J/ S m, F else cp_h<='0';
. s3 e. p0 n; y7 R% i6 H/ j end if;
/ \* l0 d8 p2 { din_h1<=cq4;din_h0<=cq3; J+ E0 Q: V7 x. a) ]8 v8 p
end if; --12/24转换
% ~. x. E( q& t + w" H/ ~- V7 I; v" ^, A9 i# k% e
end process;# q9 u& W" t! D7 A4 m
end behav; |
|