|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
module bcd_counter(rst, clk, qout);# M# ]7 Z5 U4 n0 ?6 [5 z6 S
input rst;
( D& ~8 I1 f T; ?4 S6 X input clk;3 \% p z" ~: l- f- j
output[7:0] qout;( N# r/ v, Y" _& g7 Y
& F1 [3 T0 Q8 A+ D reg [3:0] low;) y* @: r. V$ N
reg [3:0] high;& z) z, ^7 ?( C& q
9 b& H* W. m+ D% y: u/ ?
assign qout ={high,low};; b& \) S4 T$ N; ^' K4 j
* j% E0 _ O9 c- b2 ] always @(posdge clk)
7 k- V. R) s; G$ i! t/ R' `1 o if(rst)1 ?! u2 _" _& P4 I; b3 n
begin
# h) n+ q5 r3 ?" V: j) k low <= 4'h0;- t3 o2 [/ W7 @ ~* |* [2 ]
high <= 4'h0;7 \' H8 H% h% p8 |# j
end2 q( u8 w+ \3 k8 t
else. z# P6 ]$ l1 @6 i& d. c. c
begin- i( n& V0 {1 i8 P4 M0 S! m! Z
case(low)
+ F v+ v8 C$ E- C6 d 0,1,2,3,4,5,6,7,8:
3 P; F" t/ w4 u g. D low <= low+4'h1;$ T+ r$ P- B3 O! }
9:, \! K1 F/ f7 J( W6 A
begin# H: G% Q0 c8 m y* ]7 I7 j$ F7 o+ u( [
low <= 4'h0;
2 D9 Y; H& w9 i9 X I- u& u case(high)) L8 y" q6 R* S5 E( u
0,1,2,3,4,5,6,7,8:
: U5 J$ p/ f+ T high <= high+4'h1;
4 l8 Z( N0 X$ _% z/ W 9: j$ y$ U) [7 ^
high <= 0;
) K, J; a# U& I" }/ H endcase
- V0 @% Y$ Q' c4 {- S0 d- N end9 c6 e$ H1 S9 C; b( V
endcase- Y# u& {* C5 L* \
end
' {, {# G& e0 z2 G end module |
|