Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

搜索
1 2 3 4
查看: 5314|回復: 3
打印 上一主題 下一主題

[問題求助] VHDL程式計數器懇請高手幫助!

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-6-2 20:14:24 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
各位高手安安∼: R- q; e7 N* l3 O- _" @$ H: E
想請問一下
4 G1 t  V- i) @& S( I目前小弟要做一個VHDL程式
+ m6 j# @; `  F6 b動作是∼0∼9在7段顯示器顯示出來
9 X: X3 [+ c8 {: r' Z6 V- s剛開始數字顯示在9並有1顆LED燈會亮∼
0 l9 M  W+ |( \. E! h之後∼再按下SW1。數字會變成8,再按一次變成7,依序遞減到0(9變8時LED燈會熄滅)* m& T! d5 Q: l( M# H* X
然後再按下SW2數字由0變成1依序遞增上去至9,到9時LED燈號會亮起。
& |: E( J$ r8 S5 y! Y請各位高手大大可以交交小弟阿∼∼ 小弟已經認真學習了∼但真的苦手
3 t; P* d$ N$ o7 ]# s0 A% v7段顯示器是共陰
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
發表於 2008-7-14 16:21:40 | 只看該作者
4 y$ b. ~9 N9 S2 N
vhdl  的書本 及 網頁 都可以找到類似的......3 D, h$ X9 l- `$ o' v
只要自己參考一下  做個變化 應該就可以達到你的要求....
$ Q) ^5 E$ U: p6 d6 @題目不難 ...   用心就OK!!
# |/ ^* R2 b0 h2 Z9 S: ?4 L) J: W7 {! ^7 C: V$ t/ S! m
加油
3#
發表於 2008-7-14 20:44:10 | 只看該作者

給你參考一下

隨便寫一寫沒檢查語法/ z: ?( u, b+ O
前面的部分請自己加入宣告
7 \+ ]$ f% ~0 G基本上這個code應該會動,如有小細節有問題自己改一下好了6 }  |/ n8 @. Z% K
另外這個code假設開關沒有彈跳且電路有額外提供一個clock source
* ~$ ]2 K8 E+ `) L% v
. |: q, C. ?' B- Oconstant dig_0 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號
5 \4 y+ K5 ~9 t+ Q/ [constant dig_1 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號
0 G' P% V  f4 T5 V4 H  q, M5 jconstant dig_2 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號6 d' V4 _2 J0 U' G
constant dig_3 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號; q) H6 l: `# F* x& y0 O
constant dig_4 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號
% M( R3 S4 z' {4 u6 A4 ]9 Zconstant dig_5 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號
& Q7 d- g, F; ?1 N. z& R& vconstant dig_6 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號7 j: Y( K6 N8 L5 F1 a
constant dig_7 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號3 E' y! Q+ T/ [# c' X+ {4 I/ D
constant dig_8 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號/ Y$ L8 y* Z* c& l; E
constant dig_9 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號, I6 C- ]; G, c" p. {
signal cnt : std_logic_vector(3 downto 0);" j' i7 [7 d4 v+ W6 _- _# W
signal sw1D, sw1Q : std_logic;
% x* H1 {" d( Z! }. ]; p' ]signal sw2D, sw2Q : std_logic;+ _% @0 `) H% ]( K4 Z/ p! h
begin: }8 j, i2 `  M1 N" S" p9 K
, k2 d( X5 M# L
process(rst, clk, sw1). R' C7 H' P- m# `  J9 n9 K
begin& S% I# g  w% j7 b* t
    if clk'event and clk='1' then
/ ^, V) P9 [2 t0 c) I6 Z        if rst='1' then3 C/ x8 N5 K& ]! P" |0 [4 d2 T
            sw1D <= '0';
! ~$ l4 N. X- t4 M/ [  h            sw1Q <= '0';; ^6 S1 J) A0 Z  I* `$ e5 v
        else
$ d& M6 e6 ^9 O            sw1D <= sw1;6 ^9 O: W1 g7 ~; y$ M
            sw1Q <= not sw1D and sw1;
, ~' B$ Z) a2 T        end if;
  y0 a. H- A$ g. p  X    end if;' I# S, L: S0 s; B+ R0 h
end process;6 D* d7 G: Y* m8 ^
1 i8 M$ s  ]& M7 X
process(rst, clk, sw2)) G0 G; d' p: v4 S
begin+ n! \1 C; ]; l  X- ^  N
    if clk'event and clk='1' then
! Z/ f* s1 G/ M        if rst='1' then
8 U' B: |3 ^9 A9 c            sw2D <= '0';
  Y" i; L4 p) ~9 v8 R" X1 `0 ^& w            sw2Q <= '0';* p3 \/ u4 C6 `# u/ Y' q2 R
        else
7 ^5 O' W7 a9 s- Q  w, Y1 ^            sw2D <= sw2;
, e# K/ ]# @# [1 x& p0 w) z" ?+ V            sw2Q <= not sw2D and sw2;
3 H+ i) Z9 x  v# f  J        end if;
: \: E& ]8 _! I) p( |! ~    end if;
, }$ k% U  M% i$ w! ^" Pend process;+ x8 Q8 k- {6 l

# q- A  }: C  k+ r0 i6 zprocess(rst, clk, sw1Q, sw2Q)4 w5 L& H" \* I, L! R
begin/ z) V- C1 ^0 S; N( K* m0 a$ ^
    if clk'event and clk='1' then
$ K, r, {8 {0 ~9 S5 i, @        if rst='1' then
" {. r( p: e" Q- _- L. Z- J) w7 J: ]            cnt <= "1001";             --initialize to 9 when reset
% Y! u* u  p& q2 m# k! ?: Z        else
9 p6 ^: w4 [* F& l2 f5 E2 g# T2 Q1 C            if sw1Q='1' then
& Q( q% {# u3 v/ w& p/ m: w                if cnt/="0000" then cnt <= cnt - '1';  --下數時下限為0" y4 v: m9 G, E7 n, N
            elsif sw2Q='1' then
' I2 T" k. K; j  ~8 \: x2 z) n                if cnt /="1001" then cnt <= cnt + '1';  --上數時上限為9* T8 `2 ?. ]* o: B$ v9 J, b% ?
            end if;; r* h/ }& b" L# g7 s0 q, j
        end if;
8 F4 B! C$ u0 |# r9 K) A1 v    end if;
; ~* Y  J# p4 {9 S8 i3 rend process;4 @" t1 U; E3 j5 J

" K7 k+ m& D$ v' `# f; E' Y3 Tled <= '1' when cnt="1001" else '0';8 S" l4 d( H; A1 i. Q
with cnt select led_dig <=
( r5 M; S- ^4 P7 g" m& g. Z    dig_0 when "0000",
& p: |- L5 t) M' `    dig_1 when "0001",/ ?  c) t# f0 ^0 f
    dig_2 when "0010",
, b' S* |4 k. x' z3 B7 c3 N    dig_3 when "0011",4 V- u! K9 I& j0 s2 f
    dig_4 when "0100",: v( s' b! ~: Y( [4 U
    dig_5 when "0101",
5 s) t, \. b6 t8 W    dig_6 when "0110",
! o- Z4 I  v5 z9 B    dig_7 when "0111",$ K% m& _3 @5 G0 c
    dig_8 when "1000",) h" F+ H& I3 i( h: f
    dig_9 when others;8 M# N0 _2 ~1 ]
* t6 Z+ W& I% C5 {1 }7 a) z
end behavior;
4#
發表於 2008-7-14 20:47:38 | 只看該作者
在我的電腦看那個$ |+ k6 @  U; D& w1 B# x0 |1 Q
<=; h# W" a: {/ n6 `4 N0 f9 A
會變成 
. e& X% l" Q# q  ?% i  e- Z8 T&It;=
6 L# ^" y. E% k0 C! L也,好怪,有人看到不一樣的嗎?
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

首頁|手機版|Chip123 科技應用創新平台 |新契機國際商機整合股份有限公司

GMT+8, 2024-5-31 01:40 PM , Processed in 0.137017 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表