|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
module bcd_counter(rst, clk, qout);$ V5 U4 h6 g1 O. o3 G5 s. T# }7 ?
input rst;0 ?3 Y3 r: V& z, ?+ o7 c
input clk;
, C& x' |/ S5 W" t output[7:0] qout;
) ?! m5 ?: F* x
; i9 h: A @! A6 k" p. i$ o. _ reg [3:0] low;, {; \1 q8 \6 I" D; ]& d4 L/ _ _
reg [3:0] high;
6 M- V0 G+ q! S# r# N9 E% ^4 R6 K- T$ v" y* W
assign qout ={high,low};
$ [- A9 ^ [' G% O# j9 e( T( J& s/ o' \. x- J6 q9 t
always @(posdge clk); Y: D3 q% W6 q9 H8 V& T
if(rst)
2 y7 w+ @" E8 X$ r* f8 E begin
% C) U- `% G. P1 c, V8 Q low <= 4'h0;
$ b: q- Q# V+ g/ S) ]0 H high <= 4'h0;
. o- K9 U/ i* i7 {* |0 A5 ] end" B" G9 l, k. [- U
else8 E: ~7 [( ~; o7 \: n4 s! M
begin
& O. l3 e& O! J' f7 M' z4 V case(low)
' E1 N$ Y4 H* w2 [7 J% |) U 0,1,2,3,4,5,6,7,8:
0 x6 I1 Z! A$ y6 c" ~8 @ low <= low+4'h1;. }: v2 c4 R0 c5 d, L
9:2 \8 g' u( e+ @1 @- x- ^1 `2 a
begin' O; e. ^( @* k& C5 _9 n
low <= 4'h0;2 k$ d8 e" g2 l, E( f
case(high)/ Q) W$ h# \( H, Y \
0,1,2,3,4,5,6,7,8:* O3 s) a- I. }" r1 |6 C
high <= high+4'h1;
, Z/ k" B s9 Z9 Q# P V2 ` 9:: c: X6 R" u6 Y. [
high <= 0;9 q% b& }' T H2 \- v
endcase
: k U2 @# q4 S9 r0 A$ E end; N7 b* q7 H# x& ?* q6 _+ z7 a
endcase2 m% {( T* K; N
end7 H K+ z; u- U" ]6 r
end module |
|