|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
module bcd_counter(rst, clk, qout);
# K' i% d# W. k2 B1 g* Z input rst;
3 I. S: [# o5 r* ^. j input clk;% m% }6 x% u) R. m$ [$ G
output[7:0] qout;
8 Y1 F9 ]$ H. o& {8 B
' K; g4 {2 U4 p9 S( F reg [3:0] low;% C: X4 N0 F7 c4 K
reg [3:0] high;1 p) d" w6 z& X. N' W
% \: Y s; y6 _0 ]8 E
assign qout ={high,low};. `/ E- }! x0 \
7 \! u7 l" w; V6 k8 j9 ~" ^/ ?$ n always @(posdge clk). L2 g; ~7 K4 d$ Q+ V: L2 l$ W
if(rst)+ Q8 O; t5 T/ x8 T
begin
. q/ ]; B# I+ v9 V) }+ {' M1 D7 G, U low <= 4'h0;
+ y- j" V$ D- q/ |3 F& Q# O high <= 4'h0;
8 S6 T/ D+ M/ n7 {5 z. r end
6 r. w' Z1 D% M, V G else
" x9 m, Q" K/ m7 i/ d begin
6 f# I a) T/ d* w, \* I+ d case(low)
( Q5 ~; e! F' c# P) @! n 0,1,2,3,4,5,6,7,8:
* T3 B6 N L" d; y# x! `1 \ low <= low+4'h1;: ^7 b5 n3 T: u! x
9:/ J7 E0 G* U9 q. |' Y* \* M
begin$ x6 K0 M; t' x8 ]$ X4 ^
low <= 4'h0;
3 Q0 a; L; \: S" f+ e# l/ E0 ~" F case(high)# @8 P6 t& H$ f A
0,1,2,3,4,5,6,7,8:
9 y: o: Q5 T5 {, e) N high <= high+4'h1;) H! ]: W r# Y* {& h- w9 u8 d
9:0 \$ a+ ^# C: P* ?, D: @* r8 n
high <= 0;
8 @+ {% A2 n" |: ^- x4 g! G' z endcase
- n5 F4 Q/ `, k4 T. K8 J& \0 I4 f end. P/ N1 c3 ?. ?! n, a' R2 K4 f
endcase1 s9 {# W4 Q. F
end1 j i) |. Q( ]3 Y: x6 \* @
end module |
|