|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
七人表决器的程序如下
9 n& A2 E5 h, t4 I* V4 mmodule voter7(
) c! X- Y* v) T% m7 s# q output reg pass,
* f4 ]4 `& H& G input[6:0] vote
+ i6 @9 a3 _ H0 j( {9 [. @) h2 E );
# o! X" z) Q. Q& E4 x8 X5 M) Ainteger i; % ^' @0 _, j/ c I
reg[2:0] sum;
( ]5 F* U2 k5 C' c$ J initial
6 {: a, |) R8 l" X( [ begin0 f ~& p% ]5 a$ y
sum=3'b000;( v# s) P/ ?3 W4 L- Y* G' c j* b
end
% p8 L7 k. q6 b1 I& d+ N
4 h6 H# q( L* P* z5 Y& c3 O always @(vote)
- O D7 L; {3 E% q( Z2 L begin
) \ n0 o) q/ X$ T) e) a ; m2 ^( m; L3 U0 p: f4 `
for(i=0;i<=6;i=i+1) //for语句 ?1 Z% S0 F6 r, w4 C! ^( X$ \
begin ' i& X* m. Q* J) F) x/ |7 O. J& Z
if(vote[i]) sum=sum+1; ) K$ i* Y0 m/ M4 K7 C0 }
end( r4 y! n+ }; o8 q+ ^9 _$ T- C4 P
if(sum>3) pass=1'b1; //若超过4人赞成,则pass=1
7 I: @# g2 B9 `* D else pass=1'b0; 2 S0 C: f/ a% K+ H( ~
end
+ d( o! a8 u$ Z/ Z7 G; fendmodule
! R- J) P3 b' a J
1 i9 z2 C- z1 V% ?' L- C0 q$ e, o! n# i3 o2 ?
$ w! J- \5 P# |5 b; J4 A( f2 \
有提示是这样的
( x) N; A/ s" A% y N9 M+ I2 [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
! A; Y9 }. k4 }1 B9 s8 k; W, V) v- T l
Warning (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
6 d) F7 P7 }' L0 ?* X) P
/ G3 \( q) s5 n, z仿真的时候pass信号为未知状态 2 _' g" y3 D0 V& m! w: X' X
怎么办呢? |
|