|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
各位大神此设计有什么毛病吗,能麻烦你们帮我指出来吗?+ B+ S5 w* O) o$ b% E2 i, ~
设计要求,40秒倒计时,9秒之后3秒一次的SOS警示,我调试之后蜂鸣器不响,怎么回事,跪求大神指教!!!!
" m# e% B0 i" P8 s6 fmodule led_rxd(clk,rst_n,SOS_En_Sig,led,led_seg); J0 e# ] p( T) M5 I
input clk,rst_n;
1 b8 i. r$ T8 d1 J, |: woutput [7:0]led;& [, n$ [1 z% A$ I. l# V, v6 e, m
output [5:0]led_seg;
/ a) E$ P/ O0 a: j' y8 p% j- soutput SOS_En_Sig;; Z2 E/ h* N+ d. G7 [, l( G* W: H
parameter seg_num0=8'hc0,6 | L! e5 `5 b4 B$ u6 |; a
seg_num1=8'hf9,
, G6 s$ ^; ^, i2 j seg_num2=8'ha4,
o( d$ Z5 |1 }. n seg_num3=8'hb0,
; h! N! p+ w. v" Y) e seg_num4=8'h99,; D* u ~$ @, A: t3 j& ^
seg_num5=8'h92,; R5 q/ s3 F6 e8 I
seg_num6=8'h82,2 g, L1 k6 Y1 b, v
seg_num7=8'hf8,) ]8 P+ v5 O( W0 Y7 p) w$ `, M
seg_num8=8'h80,
7 M1 X' r# i2 J seg_num9=8'h90;' e: l7 M5 c1 Q6 k. x8 O4 y
parameter seg_en0=6'b111110,
% @3 t6 e5 Q- a ~ seg_en1=6'b111101,: z6 p# K7 n9 W4 ~, g3 k
seg_en2=6'b111011,
% o; }& O$ P5 E6 c8 q4 H seg_en3=6'b110111, n6 q9 @) s n. q0 R8 b! v C, o
seg_en4=6'b101111,
1 j6 s: |. p8 [; n seg_en5=6'b011111;
7 _/ l; y. |+ freg [26:0]count;
X6 F0 m* G6 r$ |reg [3:0] count1;8 U2 C: G: M$ t
reg [3:0] count2;
8 u2 V f1 S/ O- `8 Rreg [7:0] led_reg;
# L9 J% W* Z, Y' \& @4 creg [5:0] led_seg_reg;% b# y. t% `) s4 G/ L
always@(posedge clk or negedge rst_n). Z! e i2 X2 q2 y/ Z q2 r
if(!rst_n) count<=27'd0;
1 a9 x+ p: i" j( j3 f7 O4 celse if(count==27'd49_999_999) count<=27'd0;) Y9 M; \, c* p: H
else count<=count+1'b1;
8 A9 d- q. O0 a" a* \7 b/ P# Fwire clk_div=(count==27'd49_999_999);
9 b& Y$ N" s; |. @# x* u; [always@(posedge clk_div or negedge rst_n), k) `$ @# P! a( o& r0 ?9 i
if(!rst_n)
0 C7 v0 w0 [% ?, b: A! Sbegin3 |4 c$ Q) u4 K/ V, `, d
count1<=4'd0;, M, G' o' x( U( m- O; O
count2<=4'd4;
0 u& Z; x/ j5 d1 l, [0 ~end
( b/ c* ~! O# J% Helse if((count1==4'd0)&&(count2==4'd0))! C4 n+ u: {) {5 J3 G
begin G3 ^4 h1 J- P
count1<=4'd0;
4 }# b7 C: {2 o- x1 Lcount2<=4'd4;
' }% G6 F9 v9 U( a( n+ W! Gend
+ ?3 L7 ]3 g }( Z: Jelse if(count1==4'd0)6 W c: L `$ P, V& r* V
begin
( b3 k# n2 Q3 n2 |count2<= count2-1'b1;
( ]+ i# i9 R' a& L/ |count1<=4'd9;; F4 N8 n n8 x. i1 d' I( n g
end
7 P1 c) O4 L2 t& c6 R2 A0 ielse count1<=count1-1'b1;
+ J8 w. ?1 ^% z! f! Rreg [26:0]count_1ms;//
7 x/ }+ }7 ]4 e' m( [$ L; A' talways@(posedge clk or negedge rst_n)7 J. O& S: P: o" f: @
if(!rst_n) count_1ms<=27'd0; 6 z8 m S2 j0 B! Q( u; ~
else if(count_1ms==27'd49_999) count_1ms<=27'd0;" Y: m9 M: Y6 ?0 b4 p
else count_1ms<=count_1ms+1'b1;, D" J) g( Y0 `5 H K( g" [- t
wire clk_dis=(count_1ms==27'd49_999);//. q; [3 b3 ^- U& u
//, s9 g, [& c" n( h& \1 D5 [$ ^% _
reg [1:0]state;
5 h. ^, L0 ?: @5 ^4 y6 Ralways@(posedge clk_dis or negedge rst_n)
, `$ n% j/ w2 p; L- oif(!rst_n). N, h; I( s0 a0 h2 e) |
begin
' [, s+ J# x1 G. l( u+ Iled_reg<=8'hff;. D) g o" H0 N1 w4 Y
led_seg_reg<=6'b111111;3 D- @4 S' \. C) ]( K
state<=2'b00;
4 A7 t) q' s4 q2 S. Fend
, ?9 q+ A) ? O( ]2 z+ V+ I6 N# Selse if(state==2'b00)
& M) H& _+ `' g( lbegin
; H/ s c' s* B/ Estate<=2'b01;
$ l& Y3 e, Q: a- ~& D( fled_seg_reg<=6'b111101;" W8 w/ `3 c' s- y# B
case(count2)5 s! D1 s+ e( o/ L; C6 M9 Q& Z v
4'd0: led_reg<=seg_num0; 0 O0 o+ p4 z; ^( n2 Q
4'd1: led_reg<=seg_num1; . K7 s- o1 ~% U7 l5 A
4'd2:led_reg<=seg_num2; % a5 `7 O, Q5 Q: B
4'd3: led_reg<=seg_num3; / r7 v( b; A0 L2 T: t, O) u
4'd4: led_reg<=seg_num4; $ I$ I/ b0 o7 [: ]' _3 |9 Y
4'd5: led_reg<=seg_num5; , I2 h$ x8 G8 w
4'd6: led_reg<=seg_num6;
2 n# d! ~- J& V2 U! k4'd7: led_reg<=seg_num7; 2 |1 p7 D: j3 H
4'd8: led_reg<=seg_num8; & ^* U) j: V! R7 v
4'd9: led_reg<=seg_num9; " K% P2 b1 L$ d: D: }) B8 l) Q
default: led_reg<=seg_num0; 6 ]5 n. T \; y3 H' @+ h! Y! W- [
endcase
4 M; f% r. U* Lend. ~9 Y( H, e# f' @! M" i
else if(state==2'b01)- n7 J- f0 d) g5 x
begin
: d0 n( M! K0 \8 B. F5 {$ [8 tstate<=2'b00;7 ^9 N% w+ {# }* F" V8 f& s: y& w& Q
led_seg_reg<=6'b111110;9 C# {" t8 d5 N2 f
case(count1)! p, Q' T9 d" |/ B3 [5 K- Q
4'd0:led_reg<=seg_num0;3 T/ P8 y" q8 I
4'd1:led_reg<=seg_num1;: h& z- u, x/ y
4'd2:led_reg<=seg_num2;6 L( d1 j! i# r# l8 w
4'd3:led_reg<=seg_num3;$ {: C3 D8 ?% T6 G
4'd4:led_reg<=seg_num4;% m- \" v- }# h3 E
4'd5:led_reg<=seg_num5;$ x5 X& b# N' n- I. h) { q: d5 c
4'd6:led_reg<=seg_num6;/ K G7 ]" |& U2 U
4'd7:led_reg<=seg_num7;+ A* q9 |' {! |8 L* q( d
4'd8:led_reg<=seg_num8;
' q6 C6 h3 n& D; K, w4'd9:led_reg<=seg_num9;
+ G0 G1 }: f" R9 d3 gdefault:led_reg<=seg_num0;
/ C, Z0 {1 G! ]# m$ K" nendcase
: [6 q! b5 Z( m) G8 oend
- Q( d" R9 {4 d1 x% M. _reg isEn;
' d: U1 i! \9 s k0 Creg [27:0]count3;
8 S0 t* F* S5 Malways@(posedge clk or negedge rst_n)
- I% C7 r7 k% {% V5 d ~! Mif(!rst_n)
& j L8 B6 a( ^1 c1 }: A7 B6 Vbegin z+ }. }8 V5 @ l
isEn<=1'b0;% h& x! m) t; d. t8 q Q, C
count3<=28'd0;$ `6 G/ Z8 h3 k& T, U4 y- x9 }
end
- H! h' U+ k: { L% telse if((count2)&&(count3==28'd149_999_999))4 r, o: F$ `1 s# a5 K8 z5 Z
begin
$ q5 \3 r5 G( ^$ P6 ~+ fisEn<=1'b1;/ e8 z3 E/ O; m) t/ t/ M3 r; [. q
count3<=1'b0;
, j$ Z3 t& v% j ?& [end3 ]. [+ c! a6 v5 Z* o5 g: j7 b
else
+ W+ i5 w) E) X6 ~ R& o1 Ebegin
/ ^" r( z2 L, l) `9 nisEn<=1'b0;
$ _: O' S J8 tcount3<=count3+1'b1;
0 K+ U1 N( f( E6 Q, w5 s: Lend
+ r+ E% Z4 E- ?& H# ?assign led=led_reg;$ n3 C4 c6 h5 y$ s) Y
assign led_seg=led_seg_reg;
+ z1 g* r) f( N+ R# b. aassign SOS_En_Sig=isEn;0 C0 l& p4 }. | X( L( H/ U5 J# x
endmodule& e* |+ I) D$ ?2 `. X
|
|