Chip123 科技應用創新平台
標題:
7段顯示器用when else 寫法
[打印本頁]
作者:
gto10620
時間:
2008-5-7 11:15 PM
標題:
7段顯示器用when else 寫法
剛學FPGA/CPLD 現在學VHDL寫出7段顯示器。
1 i# m( j9 O$ U
entity sedg7 is
9 T0 S* l7 l6 H$ B: H! m
Port ( S : in STD_LOGIC_VECTOR (3 downto 0);
w& ?& |% @& }7 ]4 k- a! U
Y : out STD_LOGIC_VECTOR (7 downto 0);
- I6 p, q0 R$ A5 W- N
a,b,c,d,e,f,g,p : out STD_LOGIC);
/ H7 E# e3 f5 o. x8 c( P: M
end sedg7;
+ D" m* x. s) B1 i; Y( w! c
2 p; w8 u1 H4 v3 @% N/ o' y
architecture Behavioral of sedg7 is
0 n8 M) M: v3 \: {/ A$ E, k
) e; N/ t, |: V
begin
8 d c" u8 d: |! n. P
Y<= "00000011" when S= "0000" else
; p7 ]+ y% I' R4 ^1 y
"10011111" when S= "0001" else
7 z* s& i6 v: B% J0 I4 B' p& W
"00100101" when S= "0010" else
" R7 O7 B. K+ O% K0 y
"00001101" when S= "0011" else
1 }7 V$ ]2 B) P, J! W2 B! o* F5 [1 G. s
"10011001" when S= "0100" else
0 {" l$ F) {0 _& g, H- p( [1 D
"01001001" when S= "0101" else
" @1 P" t4 m5 m2 J @
"01000001" when S= "0110" else
+ l1 o4 D5 ~5 ]2 K
"00011011" when S= "0111" else
7 S( c# b) A* T9 Q7 t. {
"00000001" when S= "1000" else
/ q3 H8 J$ U! A( r
"00001001" when S= "1001" else
9 @1 i7 y+ q2 a
"00010001" when S= "1010" else
. L0 f' i) u1 g* N2 U
"11000001" when S= "1011" else
% H8 Q6 q6 i. Z: ]5 R3 S
"01100011" when S= "1100" else
# T* J5 Y3 B$ o( x
"10000101" when S= "1101" else
! u& d# p" k4 r: a
"01100001" when S= "1110" else
0 o- p5 J7 ~8 n& }/ n: j
"01110001" when others ;
4 j& V' w/ g6 m5 }& r
4 j7 `6 }, v8 e. u( r8 I5 j8 D
a:= Y(7);
) k' e5 ~1 t! R8 q# V2 v# G4 u" ]; ?2 I
b:= Y(6);
& d8 f2 D4 A s1 p- @: v
c:= Y(5);
7 k1 h$ A9 }) E6 T
d:= Y(4);
* D; e3 s8 v, ]% l+ K# a L/ l: q
e:= Y(3);
$ X8 p+ F7 p* A& N- m
f:= Y(2);
9 a" s7 x$ V; r7 b* R- v
g:= Y(1);
7 n4 `' [5 N l; y
p:= Y(0);
2 j% E. ?. s# }# ]1 x
SEL0<= '0';
, U" {1 Z8 m' g. Z( e% R
end Behavioral;
; k0 b) x# d7 _
9 f) [5 e- S; o2 L3 ]- J2 v5 {
ERROR:HDLParsers:164 - "D:/ypj2008/4e2afpga/sedg7/sedg7.vhd" Line 54. parse error, unexpected OTHERS
4 e) I. ]+ j$ x- u! t% u
ERROR:HDLParsers:3312 - "D:/ypj2008/4e2afpga/sedg7/sedg7.vhd" Line 64. Undefined symbol 'SEL0'.
5 n1 S6 o. B1 u/ j& y
一直錯誤~"~ 實在搞不懂... 誰可以幫幫我呢? 感謝~
作者:
addn
時間:
2008-5-8 09:27 AM
您好
4 f& `5 C( F. Y/ p
1.
- U- z: w* U2 R! J
Y : out STD_LOGIC_VECTOR (7 downto 0);
- Y0 F/ ]' I9 L8 V* x# w2 g
Y宣告為out 怎還可以指定給abcdefgp
7 i/ @( V$ x$ ^! p6 I
3 A* s5 l$ r! U6 Y$ k8 U
2.
) \7 S) w' u( \2 K! A* ^- M" N8 u
a,b,c,d,e,f,g,p不能用":="要改成"<="
4 S9 O' n0 \7 Y$ ?
! [% o# S) p U
3.
$ ?" O. J$ R$ I3 I- }
SEL0沒宣告,怎會冒出SEL0<= '0';來呢
: ?( F% c3 \6 F0 t5 O
7 f O. _0 \2 B+ y: u' n8 K1 t
[
本帖最後由 addn 於 2008-5-8 09:30 AM 編輯
]
作者:
airtiger
時間:
2008-5-9 05:57 PM
標題:
when else
改成這樣就可以了
2 ^( S: r7 c1 i: }
1 t# g4 I4 @# t" q6 F$ _6 Q1 A6 o
entity segment_7 is
9 k6 R- M4 {0 b; \
Port ( S : in STD_LOGIC_VECTOR (3 downto 0);
! X# r: d( ^, E
Y : out STD_LOGIC_VECTOR (7 downto 0));
2 E6 l; W; r1 U$ s! o5 g( R. W3 i; D
end segment_7;
$ m, D! V* S: n5 S# H z2 r/ |
$ L$ d8 e9 t+ b7 f
architecture Behavioral of segment_7 is
; A* b8 N, D! f# f/ W( @$ r
+ M: s8 e. I4 `+ N( |4 P& M, `) U! B5 S
begin
& j+ K- w9 H8 t, ~ L$ y& D ]
Y<= "00000011" when S= "0000" else
1 k8 B. G% ]( B% K" {% u
"10011111" when S= "0001" else
# P$ ^5 k. S' ~: O* M; f
"00100101" when S= "0010" else
/ F$ J- q% r/ Y$ H4 g5 Z3 d
"00001101" when S= "0011" else
5 W# W! O# j, n3 ~$ a
"10011001" when S= "0100" else
5 L4 @9 N) X$ h7 E# G+ A* B
"01001001" when S= "0101" else
i- K9 E( U+ m8 c' r0 s( g
"01000001" when S= "0110" else
. X/ r/ |4 ]4 b6 _/ u# o( D
"00011011" when S= "0111" else
* D/ S I* I* Z8 @2 f5 K$ N
"00000001" when S= "1000" else
$ ]7 k2 I% \( H4 @# ~* P
"00001001" when S= "1001" else
. u) C8 H4 D* q9 h
"00010001" when S= "1010" else
6 v. K4 g* T4 h. g( Q! Y* o
"11000001" when S= "1011" else
% g8 m- o' Y- `2 [0 b: P
"01100011" when S= "1100" else
, A4 t7 a _, W* I
"10000101" when S= "1101" else
4 K, b1 o/ [) s* _5 g
"01100001" when S= "1110" else
0 W, J* Z# P% F% l8 r
"01110001";
% j5 d& t# o( g8 v
: ]# \' `* f3 m
end Behavioral;
作者:
gto10620
時間:
2008-5-14 10:45 PM
感謝囉!!後來我改成這樣
# S. C7 {: }- f+ a
entity sedg7 is
* @! ~9 j- j4 W+ |7 @
Port ( Enable : in STD_LOGIC;
4 J5 W9 s& U* b4 z3 l; L
X : in STD_LOGIC_VECTOR (3 downto 0);
+ q; q9 \' \* n* M+ v
a,b,c,d,e,f,g,p : out STD_LOGIC;
" r3 d0 W$ R/ o- u: a% ?8 {) ?% q
SEL : OUT STD_LOGIC_VECTOR (5 DOWNTO 0));
( Z6 @! r% c6 {/ j
* S/ O2 P v# S$ r4 A
' O. w- v* T! C
8 K2 i$ y& g0 n# C; O- b6 a; z
end sedg7;
9 S* g F- |. g. V& ^( X* A( U
# f9 S6 E+ W3 n) I
architecture Behavioral of sedg7 is
6 O3 P7 b6 W5 b- j7 W, f9 n
SIGNAL Y : STD_LOGIC_VECTOR (7 downto 0);
1 R& ?; y: |" m, B! T& D
begin
1 c& J" w; r3 h
Y<= "11111111" WHEN Enable= '1' ELSE
% s( J; S5 r' Q: d2 X' h( V/ v% R
"00000011" WHEN X="0000" ELSE
/ [2 M( k, t2 U+ w, S5 T
"10011111" WHEN X="0001" ELSE
0 H& Q& b! Z/ C: o. ?
"00100101" WHEN X="0010" ELSE
$ `$ a L6 o* {
"00001101" WHEN X="0011" ELSE
7 u! H$ s+ K# R: z$ y
"10011001" WHEN X="0100" ELSE
, s$ ^4 v( F4 B' I: @
"01001001" WHEN X="0101" ELSE
$ J: f$ c7 v4 L; d8 A2 @
"01000001" WHEN X="0110" ELSE
" F3 T9 r! x" K+ e3 V/ f; W
"00011011" WHEN X="0111" ELSE
5 ?! `; |5 ~. A, q4 B
"00000001" WHEN X="1000" ELSE
* w; q o1 j9 K% y" g6 `/ B
"00001001" WHEN X="1001" ELSE
5 w n) a C' `" Y
"00010001" WHEN X="1010" ELSE
" S( f0 j' U" V7 H* }
"11000001" WHEN X="1011" ELSE
5 G5 p: G, { J$ r
"01100011" WHEN X="1100" ELSE
; y) D6 i0 [- y" F: H" `/ J- [" f8 A
"10000101" WHEN X="1101" ELSE
+ ]. z; Q( V9 u3 H; q
"01100001" WHEN X="1110" ELSE
9 E H% M. ?# b& b! u
"01110001" ;
: {) t, x$ F* I; e
a<= Y(7);
/ m- A) Y. C& u+ j6 o2 W: j3 b
b<= Y(6);
0 N3 L; n. y. P4 ^) t3 g
c<= Y(5);
( w2 _' ^0 T; J( k% H
d<= Y(4);
4 C" h3 T, ~7 p1 |& y
e<= Y(3);
( O; n) H- {% }3 ~5 u
f<= Y(2);
i8 m- {+ d9 i6 p P2 u
g<= Y(1);
5 i- {' y1 J8 u! [# y$ g+ Y
p<= Y(0);
( b: X. }: W4 _$ x( K( u# n+ d2 a4 L
SEL<= "111110" ;
, b. p! w D& ]+ K& y! @
end Behavioral;
歡迎光臨 Chip123 科技應用創新平台 (http://free.vireal.world/chip123_website/innoingbbs/)
Powered by Discuz! X3.2