|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
library ieee;5 D" W5 D+ j, ]
use ieee.std_logic_1164.all;2 R$ l' d' [; _/ L) a. O& y4 [( H
use ieee.std_logic_arith.all;
1 k" n3 V$ {: [9 Ruse ieee.std_logic_unsigned.all;/ p" o. q' ?* `7 B; b8 y
entity hour is
+ {, {8 Y8 ~# j* O: z port(clk_h,clk_t,tp_h,res_h:in std_logic;1 {1 O: T2 R# X5 r9 M4 f
hset:in std_logic;0 P/ h2 ]* f8 c ?
sig_h:in std_logic_vector(2 downto 0);" F( r1 R' \' ^& i% @
din_h1 ut std_logic_vector(3 downto 0);
! A! t# P" W4 Y3 z3 _ din_h0 ut std_logic_vector(3 downto 0);
- {$ l+ k0 U7 n8 n pm ut std_logic;
0 C' @/ F- f3 ?5 _$ g) X8 Z3 n cp_h:out std_logic);
$ N1 p1 z" {; N+ J/ m. t' O7 I% ] + q7 W) R3 f" d6 l/ s
end hour;* _4 Y& g' }3 L( s. t2 d `! T$ _
architecture behav of hour is
+ X, n# `7 x9 M8 x) Zsignal clk:std_logic;
; c" j9 E* M' `' X9 @8 hbegin
+ K/ @/ G3 l/ R0 \* U process(clk_h,clk_t,tp_h,sig_h,res_h,hset)' L: w* L# [# j+ ?
variable cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);# D2 I2 I: `5 p! T& F
variable co1:std_logic;# v' B5 l- r5 y' {# h7 F
variable co2: std_logic_vector(7 downto 0) ;
6 m$ x, k1 l# N( |- l3 o o5 O3 R% m begin : J& e/ D% { E/ U$ g, K
if sig_h="001"and tp_h='1' then clk<=clk_t;
7 w) u) c7 L) J) _# c8 l/ r) y% V else clk<=clk_h;
# W p8 v9 P4 s$ w. Q9 w, b% \ end if;
3 c* e, j" {/ [) Y7 M) f if res_h='1' then cq1:="0000";cq2:="0000";cq3:="0000";cq4:="0000";co2:= (OTHERS =>'0');( [" [1 H, o9 G; Q7 v8 y. G+ d: p
elsif clk'event and clk='0' then cq1:=cq1+1; cq3:=cq3+1;8 V: P4 E# Z% w6 ^% j" h2 J
if cq1="1010" then cq2:=cq2+1;cq1:="0000";
# u+ ~- i/ u" |8 r! M' B% d end if;
6 M5 [" }/ Z- }) D. h) l if cq2="0010" and cq1="0100" then$ X) P( G0 E1 [$ s1 J- w0 D/ s F
cq1:="0000";cq2:="0000";5 w- H4 H8 x! ?! J, g3 l0 l
co1:='1';! ]5 c* D+ p5 `3 w
else co1:='0';7 b" d# x2 ^7 v
end if;
o3 a, Y2 p; y, N+ U if cq3="1010" then
" _ s2 m2 Q1 C+ }/ i cq4:=cq4+1;
7 }" {% J1 X U7 Q% Y cq3:="0000";
, g# k1 {) Z3 ?, m7 ` end if;
* N7 w7 w" Y |( N: |6 y2 W% b# ` if cq4="0001" and cq3="0010" then
* b' t9 d+ n1 m& f3 x* E. W( M8 R cq3:="0000";cq4:="0000";co2:=co2+1;
# `8 G' F9 o$ \/ Z& S, | end if;
- O& z3 \! o5 ?7 o4 ], u3 m end if;# f9 t; f5 A- k8 l
if hset='1' then
: H1 K Y* I" U' F8 K* _ din_h1<=cq2;din_h0<=cq1;cp_h<=co1;
0 B5 p! @$ r! t3 L0 c* |- ? else
8 N) T0 k# a& [1 ^) q if co2(0)='1' then
1 B5 V+ ~. m9 v0 O+ b R- l if cq3="0000" and cq4="0000" then cq3:="0010";cq4:="0001";pm<='0';
1 S. Y8 Z/ O: @) l( v9 g; T end if;0 f0 v2 O2 s/ Y. t; c
pm<='1';
8 r, o& T2 s7 B h9 ? else pm<='0';: C, ~( c Q5 G$ V
end if;
* O- l! G5 J2 t, }, W if co2(0)='0' and cq3="0000" and cq4="0000" then cp_h<='1';
0 v( m) v# w' f9 v2 l& A else cp_h<='0';
" p6 c) {( |( i end if;
8 M1 {" T9 A. X+ x' W* `9 p4 p- O din_h1<=cq4;din_h0<=cq3; & [% o, B& D$ H& J: i2 v! W, a
end if; --12/24转换4 D0 m/ Y- D9 e; O4 A4 a. {5 R
. o. [$ Z( ?: d& J
end process;7 q# \" l- D3 X, {0 o4 U9 S
end behav; |
|