|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
七人表决器的程序如下+ E/ v7 K( c+ s4 n. C7 |
module voter7(
& G0 z( X/ M8 J/ _/ @( r output reg pass,
, Q& J4 X7 N) d- q- i& \1 a input[6:0] vote9 a2 s2 M9 r$ n' C0 O3 Z3 v- \0 N: [7 T+ e
);
8 b) \" y, w; binteger i; # k4 h1 ^& g0 u" q
reg[2:0] sum; + V( S0 T: N8 @9 F4 o
initial 6 K. }/ ^5 v" s+ {% |; _' M5 U* [0 L
begin
, M# D7 q5 X$ v" |8 D: F+ Y. M sum=3'b000;
' b* Q" ^7 X) m" x3 _4 F% _ end
* n, X1 z2 ]( }. V
% r% {+ X: C: b. N: s always @(vote) 0 @1 L( n+ c7 G+ Y7 m" j
begin
! D, b8 F9 u9 y 4 \% {+ |9 h+ U5 U) C s: P
for(i=0;i<=6;i=i+1) //for语句( I) s: o/ P* p0 K& U/ a
begin : `4 g' O2 Y3 I6 d: e
if(vote[i]) sum=sum+1;
5 ^3 k" ]$ }1 O end
) O: n- x& |1 I" |5 x8 u if(sum>3) pass=1'b1; //若超过4人赞成,则pass=1
+ | F3 F5 n5 ~0 q, @ else pass=1'b0;
/ r) j6 e6 L. y+ L o1 a* ?& W" d end 2 v1 x* {4 ^8 ?$ Y4 h3 o
endmodule
& U6 d/ ]8 Q' a
; d8 O p& y- e2 r
& o/ m& p) Y5 ~9 L
$ V c9 J4 A, |# g/ X有提示是这样的9 w( N# O6 r+ N! B
Warning (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! @9 t& U0 E- ^$ E+ P& a! w
# Y4 e$ d$ @" k7 v) K) _+ _, cWarning (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) k# ]6 e- M" f# }1 x
! F; d2 N# A9 i& R3 K仿真的时候pass信号为未知状态
8 z5 g6 `1 ?! P6 n+ C R怎么办呢? |
|