|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
通过Verilog HDL用数码管设计了一个40s的倒计时,想在10s之后加上一个蜂鸣器,无奈本人初学FPGA,苦试多次无果,故来此请教各位大神,能帮我在40s倒计时上面加上一个蜂鸣器吗,跪求了,谢谢!!!!module led_rxd(clk,rst_n,SOS_En_Sig,led,led_seg);/ t, U, o! O( k7 b
input clk,rst_n;; V2 w; P+ E# c# C+ C
output [7:0]led;3 B& q. a1 ^- @6 T
output [5:0]led_seg;/ _: X- D3 s o$ n7 _+ ?. S
output SOS_En_Sig;
; ~7 T6 ~% w% Gparameter seg_num0=8'hc0,/ D7 ^2 _: V. Y
seg_num1=8'hf9,
. F" `- _# O0 F1 r1 O. t5 N9 q seg_num2=8'ha4,
, G: A) C1 I- N* M1 Z seg_num3=8'hb0,
1 H/ h. p/ ]0 U1 K+ |, y* u2 P seg_num4=8'h99,7 p+ O" m3 m/ L2 ?
seg_num5=8'h92,
N. {6 J5 I- n5 `( `. K* Z seg_num6=8'h82,. c+ ~( n0 p; B
seg_num7=8'hf8,* M3 L7 J- j) S6 n1 f" c
seg_num8=8'h80,
& N3 G; k, s H. z) K- Q- Q seg_num9=8'h90;
7 ^( i! f6 P8 v6 D4 h0 Y. Tparameter seg_en0=6'b111110,
( v, I7 }$ D! a& U2 j9 Z# w" @- S* C seg_en1=6'b111101,3 [9 e1 t* Z7 \! |6 T% J
seg_en2=6'b111011,4 R; o S. h; ]# W' d; q
seg_en3=6'b110111,- {' v, H9 i& u: R
seg_en4=6'b101111,: r" |8 a3 T6 X: u3 i
seg_en5=6'b011111;
. K$ z% |0 i6 L$ r3 l' u2 [reg [26:0]count;$ m* v7 {/ l: I. B8 c( V
reg [3:0] count1;* {) _1 _9 M6 O5 `/ N4 I
reg [3:0] count2;: d4 M7 [# e& s' C& v7 S
reg [7:0] led_reg;+ } {4 o0 t9 K# w
reg [5:0] led_seg_reg;
5 [) R5 T9 `, Q, z! [4 dalways@(posedge clk or negedge rst_n)
+ j+ A: ~, c+ Xif(!rst_n) count<=27'd0;
/ m/ w3 n0 \- B" _else if(count==27'd49_999_999) count<=27'd0;
! i f9 `# d' l( @1 E- n% d' Pelse count<=count+1'b1;
; e* ^# n/ p5 W! ]wire clk_div=(count==27'd49_999_999);) Z; E* ~4 e( k* x
always@(posedge clk_div or negedge rst_n)1 g8 g3 ?' h7 a" W, `: z5 @
if(!rst_n)
( H6 i: l/ N, z$ ?# Xbegin
( E. L4 z" j- ]count1<=4'd0;
& c; g) D$ `2 R0 ?4 q$ B9 G9 ccount2<=4'd4;# W. I3 ] Z- z3 w$ y
end
* \ y; B( U& m, x7 p4 P" X; R1 Delse if((count1==4'd0)&&(count2==4'd0))
' n( k7 H( z% x1 O& T7 d# ebegin
1 Z5 I/ J+ i# ccount1<=4'd0;
- `. z2 E! C" x9 i: Zcount2<=4'd4;
$ Z9 m$ E$ ^1 |. x' Y+ }. eend( M$ A$ @% L8 {2 D2 j/ d) j& d! l
else if(count1==4'd0)( ^& c# s/ ^! {
begin9 T1 p8 `" ]( |2 }# T# h
count2<= count2-1'b1;- k. L. F2 A3 z- \, W: ]
count1<=4'd9;4 m( s, ^7 Y# W1 y i# [1 {, X
end
0 f( f6 }' b9 Qelse count1<=count1-1'b1;
# J$ `; t2 M% Lreg [26:0]count_1ms;//9 _! k e: g! a
always@(posedge clk or negedge rst_n)
. n8 Z( P$ p8 O8 w+ ~+ Q3 pif(!rst_n) count_1ms<=27'd0; / D" T q; x. E, m* l
else if(count_1ms==27'd49_999) count_1ms<=27'd0;
+ |$ c* J; A+ N( Jelse count_1ms<=count_1ms+1'b1;
; m" ]+ j5 N( a* Y# Uwire clk_dis=(count_1ms==27'd49_999);//
* X: H; R) j$ c2 K//
, v" L. i0 F0 U/ lreg [1:0]state;1 U. B% P$ T$ ]' r
always@(posedge clk_dis or negedge rst_n)* _ t+ l0 ?1 M9 m
if(!rst_n)) Q9 W1 L' c) Z" b
begin$ a2 K9 u4 S3 y9 W) s g
led_reg<=8'hff;% a. c8 Q5 G% Z
led_seg_reg<=6'b111111;
. Z4 S! ^. \% V1 Pstate<=2'b00;' t) g2 G3 S* m% w8 r1 n% o5 w; T
end8 B- g3 a' N' h, Y! m* T% S
else if(state==2'b00) 8 Y! Q ~# N5 t. B' K
begin
2 h+ H! [1 u* p- L7 |state<=2'b01;
$ B3 I. Q, W# I" k! Dled_seg_reg<=6'b111101;: T( R3 [$ M/ ?* o- l
case(count2)* ~5 H3 v1 `! N0 b8 D+ o7 ]
4'd0: led_reg<=seg_num0; g3 Y$ q) T m) Q
4'd1: led_reg<=seg_num1; x6 R5 }8 Q! J8 F& N
4'd2:led_reg<=seg_num2;
0 I: a2 y0 {: T: C! o& i. w4'd3: led_reg<=seg_num3; 0 m G8 H5 i1 c" c, v
4'd4: led_reg<=seg_num4; , r2 k6 h+ U6 c
4'd5: led_reg<=seg_num5;
# O, P0 c( N0 f( p( u4'd6: led_reg<=seg_num6; ( L* X- t4 ]) _4 f& P! {4 B
4'd7: led_reg<=seg_num7; , }. q/ G/ H/ x- e
4'd8: led_reg<=seg_num8; 8 A, w/ T' K! C
4'd9: led_reg<=seg_num9; 9 t" I$ B/ _- }% g/ L) Z- c" L
default: led_reg<=seg_num0; % L( t/ C/ J2 }7 y& X* D. r( T7 w0 z
endcase" D& ?8 m4 L9 z" a- f$ ~
end
# p$ p$ P3 o# j% n* i9 G9 jelse if(state==2'b01)9 `1 a7 S4 X( P) u8 d6 \& z
begin
% T' A: O4 y: _7 i* {$ x! s: ^state<=2'b00;1 K' E2 z: {8 g9 {3 ]& x. H
led_seg_reg<=6'b111110;
h6 c, k+ N5 |7 i9 x2 Rcase(count1)
5 H3 e( I' l5 t# d: Z" U$ ~& }. f4'd0:led_reg<=seg_num0;
0 e3 P ~" s9 [$ z( w' q4'd1:led_reg<=seg_num1;
: v( X5 D- h7 ~9 g$ u. h4'd2:led_reg<=seg_num2;1 ^4 `6 M2 S2 x( o L) b. A
4'd3:led_reg<=seg_num3;: S. L* d2 _4 A# l* k
4'd4:led_reg<=seg_num4;! O" t4 w4 h& C$ \& d/ h
4'd5:led_reg<=seg_num5;
5 r3 q) W3 J5 a8 T4'd6:led_reg<=seg_num6;% N* b" ~1 x6 n$ R
4'd7:led_reg<=seg_num7;5 }3 M! H. Q5 V# d) [: g) [
4'd8:led_reg<=seg_num8; ^1 d/ A g) ^+ {, R4 }' ]
4'd9:led_reg<=seg_num9;# s0 u3 h, t, h! u
default:led_reg<=seg_num0;7 {9 |( Y% ^4 y! E m; b
endcase
) ~/ w) m. c) t4 ]) j9 |end) l$ m4 D: I) H3 j9 y) j, d3 n
reg isEn;8 h+ h4 f: d2 Z/ ~8 C* \% x m
always@(posedge clk or negedge rst_n)
6 M, d0 w4 C+ j- Rif(!rst_n)& V3 m6 w4 q3 Y! p6 c) D. O
begin
# J: B% D# A' S6 eisEn<=1'b0;
0 ~. }3 V. _5 ]! n6 Iend
; B; I. _) o6 k' Ielse5 j. r1 B; T$ O" E# V
begin8 [+ t7 b+ z f6 Z( A1 i6 q& ~
isEn<=1'b1;2 k. l: u9 M H7 d7 G& {
end
5 \8 I% J! ^, { H2 \+ tassign led=led_reg;
$ ]) J+ P* v1 M, @assign led_seg=led_seg_reg;9 z# P( |6 y% w/ e) K1 Y
assign SOS_En_Sig=isEn;# S0 N: ]: ~* h% y
endmodule' u# ~( ]; t, C0 m7 s" S, m
$ V6 ~; Z( ?$ B# z, d |
|