|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
七人表决器的程序如下
7 U' E7 t) f2 nmodule voter7( 7 `/ Y" S1 j* D+ Y
output reg pass,
' W6 T* z. z; [2 G$ ^7 o# A# r input[6:0] vote
- U2 n( h |& v. N# g; Z );0 J2 `2 w( O8 }
integer i; " n! H+ ]& Q3 h3 ~4 U
reg[2:0] sum;
8 i' ]) t2 I0 ]( r; @- y" h- D initial
5 n6 {) Q8 b: `0 u9 m& R begin! W4 C' t* ~/ O$ a0 @. M$ z/ W! }/ u
sum=3'b000;: A3 x0 y( G! m c6 ]) M- ]
end+ T/ e6 D+ w3 G* A' u
# R7 o' b7 g; v+ s2 \& e* S5 G always @(vote) , n( d! O# X1 m/ L- E$ i
begin 4 |/ t" e; |* m+ [* V' K
8 i0 P( G/ y9 o9 i$ D for(i=0;i<=6;i=i+1) //for语句' M6 H4 j3 y1 s
begin
S) y( F9 h( }8 l( q/ {3 G+ P3 T if(vote[i]) sum=sum+1;
' L9 v1 ~+ n% _; i1 f- _, H end
( c/ W7 u z( X2 P( Q/ j if(sum>3) pass=1'b1; //若超过4人赞成,则pass=1 5 j, ~& ~4 |/ R& \
else pass=1'b0; $ C; m+ P1 c; o( u( A
end
) E* d8 F/ _, n" }endmodule % F: q' e& e$ H8 M% H) Q" U
& s6 ^( D, g! ^6 g# k
- \6 v0 k, O7 `- p; _0 Z- a `: r0 w$ D3 H; a+ F4 ?
有提示是这样的
c! n5 j a# `, s- R; N) DWarning (10235): Verilog HDL Always Construct warning at voter7.v(18): variable "sum" is read inside the Always Construct but isn't in the Always Construct's Event Control/ D7 e' s% g2 _
; q9 r& }: E. C- X1 V3 PWarning (10240): Verilog HDL Always Construct warning at voter7.v(13): inferring latch(es) for variable "sum", which holds its previous value in one or more paths through the always construct
+ ]4 i0 n. D+ P6 r" m2 l
! u2 a) L9 o8 H* A- @: f仿真的时候pass信号为未知状态 - @! t [, j* F% x! W; L
怎么办呢? |
|