|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
通过Verilog HDL用数码管设计了一个40s的倒计时,想在10s之后加上一个蜂鸣器,无奈本人初学FPGA,苦试多次无果,故来此请教各位大神,能帮我在40s倒计时上面加上一个蜂鸣器吗,跪求了,谢谢!!!!module led_rxd(clk,rst_n,SOS_En_Sig,led,led_seg);( G: B# J; c. y0 _6 c
input clk,rst_n;0 i: z: ^ k0 z* e# H: s
output [7:0]led;) Z2 u! Y1 J0 c& O2 p0 N- l" f0 T m& K
output [5:0]led_seg;* r2 X' b" ]- [# X ^- ]
output SOS_En_Sig;
$ |8 \5 i; B* s4 F- v( F4 Z! Wparameter seg_num0=8'hc0,% ^) i0 d- y2 A& `2 X j2 V; L
seg_num1=8'hf9," ? e) m6 F ?' R
seg_num2=8'ha4,
1 F$ t1 \/ x1 v5 h seg_num3=8'hb0,$ G( a7 \: l! J% F3 |8 p" @
seg_num4=8'h99,2 a9 U- w/ { j
seg_num5=8'h92,
. E9 d8 b" {3 }+ x/ r+ [ seg_num6=8'h82,+ m+ m; f3 t. Q* i. I. Y
seg_num7=8'hf8,3 |/ x5 A: V+ Z8 y$ r
seg_num8=8'h80,
1 }% ?5 [5 \: Y; A: o seg_num9=8'h90;
# w7 q+ x3 {( uparameter seg_en0=6'b111110,3 L' t& b7 q; l# b; ?8 ~
seg_en1=6'b111101,
7 U0 U1 @8 P9 B' G" } seg_en2=6'b111011,( f7 s5 o: D- G% y& { s: P: n
seg_en3=6'b110111,
; l' |5 d" u5 b& \ seg_en4=6'b101111,+ f8 O c7 V1 P0 `
seg_en5=6'b011111;
' L3 j. G1 I) L5 Y n X! t5 ]reg [26:0]count;
6 ?, ]2 Y' \, v: N, [7 E2 k& J0 Dreg [3:0] count1;
* B" S* v7 n. g2 I( Xreg [3:0] count2;
l" u1 k- i* ]5 Z" f% ^reg [7:0] led_reg;
, k% P0 C2 n* Z1 |7 m# \reg [5:0] led_seg_reg;; J& c6 }5 g0 B z
always@(posedge clk or negedge rst_n)
/ j3 j; o4 e0 y- ?if(!rst_n) count<=27'd0;+ v( d6 A& N# @5 m1 D, V& g
else if(count==27'd49_999_999) count<=27'd0;
, [9 W/ G- p* g; `; O# x6 telse count<=count+1'b1;
$ C( e; T+ @8 S7 Cwire clk_div=(count==27'd49_999_999);2 J% i1 H* C/ Q3 i
always@(posedge clk_div or negedge rst_n): M& z. j5 {; l4 s/ P
if(!rst_n)( i1 S% Y9 g% n2 J' {
begin* r8 t8 W" F* m% Q* z# M- }# n
count1<=4'd0;! k% a% ~; c/ ?" u2 X* _
count2<=4'd4;# ~1 C9 ^" F4 B% E/ ]9 p
end
( k7 Q/ L8 i/ H' ~4 b# {else if((count1==4'd0)&&(count2==4'd0))
' h% C* `( W# p6 P9 gbegin& X8 z; Y: o( K k2 [) A
count1<=4'd0; ' S9 E+ V, x5 [- V( r
count2<=4'd4;
$ Q, R) b; E& z8 {% ~end5 h: g- x& b5 ]3 i
else if(count1==4'd0)
* c* r V# K5 X/ pbegin6 J) h$ m* y# w0 }6 J
count2<= count2-1'b1;
0 K* P4 {% y5 L2 l; rcount1<=4'd9;
/ n% b- }: z( k0 Dend
; Q3 W! h* w, U7 Zelse count1<=count1-1'b1;
- A" I3 X. O7 Y1 a \1 Breg [26:0]count_1ms;//
: n7 h: R2 a5 A* I8 oalways@(posedge clk or negedge rst_n)! m5 _. A% d( s' T! [ a
if(!rst_n) count_1ms<=27'd0;
, |8 ~3 W- u' h$ H) Zelse if(count_1ms==27'd49_999) count_1ms<=27'd0;
|8 T7 l: d$ selse count_1ms<=count_1ms+1'b1;
& n" c# N6 z9 Q, F6 E0 ~! {wire clk_dis=(count_1ms==27'd49_999);//% G' p" ^% k, F# [* u5 }/ u; _
//, h( j8 s; l; o' q
reg [1:0]state;- j8 p. R" C2 n0 D
always@(posedge clk_dis or negedge rst_n)
/ s j+ P( [, x* a& I! a( j5 cif(!rst_n)
' v' T1 Z7 E! d8 }, [% W p2 s gbegin: |% A) D# `2 H z* ?' i9 b. U
led_reg<=8'hff;
; Y4 r; s) Q7 e, N, @4 oled_seg_reg<=6'b111111;
; F" u, j" e' k' estate<=2'b00;
( h+ q" l6 i, I$ Y3 _end# i7 | |$ }2 h! H: s
else if(state==2'b00)
5 B2 f" K- i! R- A4 f5 e3 vbegin
: `- g) V4 d, L) {8 w6 ]# N. t0 [state<=2'b01;) @7 u% x0 ^* r
led_seg_reg<=6'b111101;6 O* R' x. Q" g
case(count2)' P/ ~0 e6 _7 P: T; G5 g
4'd0: led_reg<=seg_num0; ; A% j& P' M6 t7 }: E
4'd1: led_reg<=seg_num1; ! t8 B! |/ m4 X7 L Z" x
4'd2:led_reg<=seg_num2;
: A6 u. p+ f3 u* r" y N4'd3: led_reg<=seg_num3; 6 t5 i% T! C8 e, a
4'd4: led_reg<=seg_num4;
; F1 j9 Z* Y) I! d+ Y$ C4'd5: led_reg<=seg_num5; W/ }$ I- X; \2 f) ~6 N
4'd6: led_reg<=seg_num6; : s- _7 E3 {1 |" B
4'd7: led_reg<=seg_num7; 1 T) ?2 T& ?' c6 t
4'd8: led_reg<=seg_num8;
; D0 F3 R, j% }9 g) A/ x+ z3 n4'd9: led_reg<=seg_num9;
7 a$ x; w4 [7 `! {) [4 O3 H1 Adefault: led_reg<=seg_num0;
9 @0 F9 a' d% Q- c# k" Eendcase
3 ^0 M! b9 u" Uend# N" \# o7 U. {5 F- ^+ @, U
else if(state==2'b01)6 }7 J" e6 z0 I& a
begin 9 f1 b1 A. d& f9 g: A3 f5 t4 I
state<=2'b00;
/ U* t9 g) h) K9 Z, E4 Mled_seg_reg<=6'b111110;2 r6 C2 Y+ a0 X) }+ ]0 u* }8 \. i) \& D
case(count1)
3 c5 n8 h [# T k6 X8 q4'd0:led_reg<=seg_num0;
6 |8 U6 J) `6 y4'd1:led_reg<=seg_num1;3 z7 {- N! J# q% ?1 H1 [
4'd2:led_reg<=seg_num2;8 ?" Y0 k1 x8 z8 ]! l# m% ]$ e
4'd3:led_reg<=seg_num3;
9 {' d2 F1 h w4'd4:led_reg<=seg_num4;7 d4 b9 D& \9 o
4'd5:led_reg<=seg_num5;
. w' N% F3 M" P1 B0 R" N4'd6:led_reg<=seg_num6;
8 x1 }3 y+ e) Q8 G) x4'd7:led_reg<=seg_num7;* e9 z( k. e- P f4 d' }7 _
4'd8:led_reg<=seg_num8;; t- M# _. v+ Z/ c& g) ^& {
4'd9:led_reg<=seg_num9;
+ G8 y- i J9 J$ d* p! v8 l* H5 ndefault:led_reg<=seg_num0;
& Y$ z9 {0 X" j& P3 Y5 Lendcase2 y1 x1 d% h2 L0 Z- _# }1 ]$ o
end. y: M$ v7 f- H9 J
reg isEn;
% T/ d2 A/ L& m2 M* E0 b# i6 Lalways@(posedge clk or negedge rst_n)
4 W3 G+ f1 C7 v6 Sif(!rst_n)5 v+ s1 v7 f$ o. u
begin
! p# `& V9 S( }$ [, g4 GisEn<=1'b0;7 u* {) q3 m6 R- q7 h
end8 S$ q/ J% Q8 x$ h0 x( a
else, Y( y( R& k( E$ V
begin
0 d6 X( h6 K) V2 C; WisEn<=1'b1; x0 q& u/ P& u* }" H: G7 O! m
end6 v" O/ {( P0 e1 {5 D8 e* A2 s
assign led=led_reg;" g0 V# J- {4 B0 E3 L! D% v9 |
assign led_seg=led_seg_reg;" \: @/ s$ P) x
assign SOS_En_Sig=isEn;) N5 ]' g( V9 Q: D5 g# T
endmodule# ?; N" n3 L! ^1 w
. W2 S; d( Z' ?$ [+ A' v2 T, g |
|