|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
module bcd_counter(rst, clk, qout);5 S4 r% p' C: x# M
input rst;
" }! p G' L6 o8 S) w2 M8 l! j" y input clk;0 L% W1 u3 |: ~; u
output[7:0] qout;! ?! s( t7 h& J9 U2 h
" S& c/ g9 W0 v: N reg [3:0] low;
' {0 K8 M @* x9 h, C U reg [3:0] high;
; `& x5 k- k3 \' e. i" t) M" g9 n1 A* G3 J- }: C* ?9 A7 y# [
assign qout ={high,low};+ m3 a# B+ I5 O9 Q1 J
6 ~ T M% | H% A$ O8 s always @(posdge clk)
6 K6 Z6 Z2 ]0 E! y9 s* V if(rst)8 B' R+ C5 v/ d: Z
begin
: z" @" B& J! a! P/ q4 M low <= 4'h0;9 v9 \. p0 L$ z: u1 y5 y
high <= 4'h0;9 n1 [9 L i/ [1 V- D w
end
2 M6 B' G9 I$ v1 e; L else% V" f& _" Q0 w; s4 K
begin
9 S3 E/ n! F; A9 a0 X" L case(low)
4 n5 U# S9 L, N* Y0 I' g5 W 0,1,2,3,4,5,6,7,8:1 m% w: H: A) [, u7 P
low <= low+4'h1;
5 `, i( L- Q# W 9:
4 x# R: \, K5 b/ e [+ N# r6 e% i begin9 n, [& o* e( X8 [0 z
low <= 4'h0;
( A/ s4 ^3 f x8 V4 O( H case(high)0 ^ L1 Q# s' g# k5 {
0,1,2,3,4,5,6,7,8:( K& ] D& j: e# G' D
high <= high+4'h1;
6 \3 a$ l6 s: `1 L2 H 9:; V/ w0 j/ ` P2 E: H; _4 u
high <= 0;9 n7 _2 S2 g' r4 a; K1 K4 S
endcase
# m) {8 I$ r% x" \, w) Q end
! J( T6 `) M2 r endcase
5 |8 ]5 y& L* K5 T: F" C( [9 Y end9 f* a4 f- F# R: S2 w
end module |
|