|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
module bcd_counter(rst, clk, qout);) }/ z& h8 c8 ?
input rst;' a3 o& U" h0 k; ^5 t0 K3 k# @
input clk;* Z% H- g4 o7 e5 o1 I1 x: p
output[7:0] qout;
. T7 d ]7 ?4 K0 h; s- E6 g( Z; r1 n% S' J7 o5 Z# y
reg [3:0] low;
' {; N5 [/ M( ]* E4 T8 y reg [3:0] high;
, i0 _) I" N9 ^0 _' G/ i6 L# W& B
# @ s& L; t; H; t. a1 J assign qout ={high,low};* v# \2 j1 B; n+ z2 h0 g' S5 `. O
9 {6 \( n7 ?1 M/ T9 |( S& s always @(posdge clk)8 y9 E2 ?. w* c" j2 W) s* z
if(rst)# _8 x" i! U7 I4 s
begin
1 L) t4 d+ h2 q* k8 V low <= 4'h0;
1 \" B7 a7 [8 U0 ^6 w high <= 4'h0;5 O% r8 K, d) m, a: [
end+ {, w# R' g8 o5 x6 k) x
else& O0 u4 `' \4 O* i+ {- O
begin
2 j% C7 C0 W% j+ a3 g case(low)+ S4 o1 r1 R* E6 M
0,1,2,3,4,5,6,7,8:
; V: f+ N- M. Z$ F0 y7 ?6 Z" h. U low <= low+4'h1;
X/ l; x* h+ y0 N% R1 F 9:7 ^. N* h6 f6 a: I5 N
begin
3 d* T+ Q# _6 \7 |! q; [ low <= 4'h0;' G( |, X0 U( o8 W1 r* r4 Y
case(high): ?5 s9 k# j' R/ A1 V
0,1,2,3,4,5,6,7,8:
0 G5 Z( C- S# s {0 O1 T' o; _ high <= high+4'h1;* f; v* D8 y5 l0 o7 e
9:
. K9 W& k; N6 R5 K+ r0 z high <= 0;
! B; B1 z2 B) i, _8 B7 `, {$ y endcase; ?7 Q4 r, a$ M; f5 l+ S* I
end3 D: T! W! a2 }
endcase* R7 Z6 y9 M0 Y0 M4 ]2 P
end j- e* E- D6 `. \7 J- I) E6 c
end module |
|