Chip123 科技應用創新平台

 找回密碼
 申請會員

QQ登錄

只需一步,快速開始

Login

用FB帳號登入

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

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 2008-6-2 20:14:24 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
各位高手安安∼
! V5 i% @) Y1 p2 `( m& c4 p" v想請問一下
+ F: s5 k  j' G9 @# s8 I9 s1 h7 c4 G! ^目前小弟要做一個VHDL程式( w  ~5 V$ h, B  |, d# a
動作是∼0∼9在7段顯示器顯示出來! k6 p/ X# c# a# i1 H
剛開始數字顯示在9並有1顆LED燈會亮∼' Q$ Y0 B) V4 @9 H  q- Q  I: `
之後∼再按下SW1。數字會變成8,再按一次變成7,依序遞減到0(9變8時LED燈會熄滅)
. M/ P7 m# C6 Q3 F, `; r$ p4 s( k然後再按下SW2數字由0變成1依序遞增上去至9,到9時LED燈號會亮起。, i+ m1 Z$ t# F8 ?7 y7 Z
請各位高手大大可以交交小弟阿∼∼ 小弟已經認真學習了∼但真的苦手
. z; w0 a$ x: D7 x7段顯示器是共陰
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 頂 踩 分享分享
2#
發表於 2008-7-14 16:21:40 | 只看該作者
4 q$ U7 B8 w* @5 V- e
vhdl  的書本 及 網頁 都可以找到類似的......; r0 [' _3 y- M6 ?2 g: X, x: ^7 y
只要自己參考一下  做個變化 應該就可以達到你的要求....
- _0 t' E( n2 U( v( ]題目不難 ...   用心就OK!!) Z# b/ j. E5 A$ L0 s. I

3 P* [/ A2 K3 `- P; C' p加油
3#
發表於 2008-7-14 20:44:10 | 只看該作者

給你參考一下

隨便寫一寫沒檢查語法; y) w. x8 Y9 T" P
前面的部分請自己加入宣告1 Y; y& f. Y6 a+ S: |: G4 p1 e
基本上這個code應該會動,如有小細節有問題自己改一下好了
* K6 R2 r+ t. L9 h& V# z另外這個code假設開關沒有彈跳且電路有額外提供一個clock source
, m; D' U  M9 a; `* p8 j) ~
% S, m. v, |, L1 x( [) Vconstant dig_0 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號3 E# E' M- o) V
constant dig_1 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號6 S3 d9 _2 a8 F; E
constant dig_2 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號
. g$ V5 z3 P! t+ ~" d8 V$ Z; Y  vconstant dig_3 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號0 T' u$ o* ?5 q# r- S6 M! f
constant dig_4 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號  G& R3 h8 h8 R! U
constant dig_5 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號
$ a  w3 j, {' G" {constant dig_6 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號4 \" n8 {3 B0 w7 n' N1 d' y
constant dig_7 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號
. a1 D; z; C- p; R1 O( ?% zconstant dig_8 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號) {  {" o. b& q. g4 G7 u5 t
constant dig_9 : std_logic_vector(7 downto 0) :="xxxxxxxx"; --請自己定義共陰的信號" e9 w% e* g$ S( d1 s0 r
signal cnt : std_logic_vector(3 downto 0);/ T4 d9 n1 K3 C; \- x) p% l
signal sw1D, sw1Q : std_logic;. ?: Y) g7 V0 t4 J* y
signal sw2D, sw2Q : std_logic;
& j6 F$ l/ D# @) @3 ^begin* p3 o" C7 c* v; N+ J& C! x9 [% H
* u( |2 j4 ?$ [
process(rst, clk, sw1). _+ F2 I& i3 ~: D4 {
begin
. o6 `' i0 a) y% z# M    if clk'event and clk='1' then
# a& A1 F4 H  Q        if rst='1' then
6 b7 Y, D9 e: F9 u2 r            sw1D <= '0';
7 R5 |  T* i! G; C0 |            sw1Q <= '0';
! D9 n" w, W- D) f8 C/ L& ~  e$ Q        else
$ n/ J, ?3 M) Z6 b* \8 f            sw1D <= sw1;$ R" m( f- X+ b( F
            sw1Q <= not sw1D and sw1;& m" {- {& B& U8 j" ?# i0 ]
        end if;' N6 D# Q, i" i  r! C
    end if;* b4 }; h% y0 v# q+ Q  U) ^
end process;
0 l2 |: ^5 Y6 S- l2 d* V
/ ^) T9 ~# x, _& Uprocess(rst, clk, sw2)6 |% `' g/ e( t1 c8 L3 E
begin
/ P% a6 E/ S# u    if clk'event and clk='1' then  y3 o; r" _7 E$ K: r
        if rst='1' then8 g6 p( V, X6 }5 V' A4 g
            sw2D <= '0';
: X& E& d- k) m/ ~" A( M' W8 T. a1 S            sw2Q <= '0';. `. W/ n- B- c4 F! R# Y9 ~* c$ K
        else
( U' A4 q* g' r/ K1 x            sw2D <= sw2;
2 z* c2 f. [( r# i4 n            sw2Q <= not sw2D and sw2;1 N  i6 c# u( C1 U
        end if;
+ n' [2 L3 J. u. C9 E    end if;
- [/ D2 `9 K" rend process;
$ l# \+ K/ }: W  J  `: r& M* N; b0 b3 {) s
process(rst, clk, sw1Q, sw2Q)# j- X/ m( l$ v
begin1 d6 N! K. z6 q  h1 y3 _
    if clk'event and clk='1' then& J4 {, c- X+ n1 o) |7 P  c
        if rst='1' then
/ x( y9 ~5 h  A) x            cnt <= "1001";             --initialize to 9 when reset
, ]8 G- q/ a& R0 R. d( P( J        else
- _' v4 j- ?8 @# u            if sw1Q='1' then
& W! S) L0 D3 T9 m                if cnt/="0000" then cnt <= cnt - '1';  --下數時下限為0
0 g: Y- h/ D8 d; H            elsif sw2Q='1' then
( s2 z  V1 o- }- K                if cnt /="1001" then cnt <= cnt + '1';  --上數時上限為9) j% S5 N8 J; }2 n% |' I
            end if;. M* A' y8 f2 {. L: |9 T
        end if;
2 X1 z8 W* v$ I! V    end if;
  q$ k6 o6 \3 J" c8 A# \end process;* q  ^) Z6 n/ c
3 E7 G. O! D) Q8 x
led <= '1' when cnt="1001" else '0';
, i- }- z; |4 T. Dwith cnt select led_dig <= $ e) E9 Z, g' {$ M6 p+ {* Q
    dig_0 when "0000",4 r, b8 J. D  O' E9 j7 z
    dig_1 when "0001",
0 Q! }$ @2 {- Z' u6 Z    dig_2 when "0010",
% C6 O* `3 }. U2 D" b  ^5 {    dig_3 when "0011",1 g3 {9 v/ Z  u: n2 A- X7 ^8 C
    dig_4 when "0100",' a/ G0 P4 Q; ~2 V
    dig_5 when "0101",& S4 [- M8 C8 q( }- t8 Z, a
    dig_6 when "0110",4 R# w6 s# l/ Q; s
    dig_7 when "0111",
4 p# O4 T7 e+ l$ a* ^9 c# F    dig_8 when "1000"," A8 N  E) B3 K
    dig_9 when others;3 h% e1 Y/ |* e  T1 n* T' [

2 _+ {0 c- F/ Z. Z! U( y7 W' M9 z0 l" fend behavior;
4#
發表於 2008-7-14 20:47:38 | 只看該作者
在我的電腦看那個5 c# H. \( v# H& L3 t* a/ W
<=
3 d$ l1 Y  l8 b, V, R3 {1 w& H會變成 . }" ^; |4 F6 r% v
&It;=
  V2 d& i" I8 n0 c. i  \也,好怪,有人看到不一樣的嗎?
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-4-28 05:19 PM , Processed in 0.108006 second(s), 17 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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