|
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次9 m# k x! H5 y. v" Q0 o( |& w5 T1 F
就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,+ W. b# s' \) x7 r& y9 A
希望能有高手幫我解決此問題4 k$ d0 \ F% W6 c* r5 q
' Z5 `. B4 @/ U. z# k1 a
0 K9 P$ ]& E7 _( |$ Glibrary ieee;* f% {# g. t ]; ]0 A
use ieee.std_logic_1164.all;
2 |% J4 d# g" m, I0 Euse ieee.std_logic_arith.all;
: @. |% t( p, U6 Z1 X j3 M" Juse ieee.std_logic_unsigned.all;& _* O+ W; t0 M& c
2 z4 `& Y- g! i+ m! D$ F" @entity pwm8 is Port (
+ L e5 N8 x) C. j/ C2 ?1 O0 l+ n CLK : in std_logic;--clock 1KHZ
8 @% c3 F( G- C0 | RST : in std_logic;--reset9 Y3 c0 {) ?4 ~) j
SW : in std_logic;--switch in2 U/ Q9 l" T! s8 R: {& O& b( W
SEG7 : out std_logic_vector(6 downto 0));--3 X2 b, y, E6 V7 v1 o& N9 M* y$ b6 d
end pwm8;
7 l/ P* x4 W$ x* o
8 q/ K( l$ j* T; o# {architecture arch of pwm8 is
( U2 Q# B! y$ G6 U* w1 _% X0 f' d: [! d8 x6 I! W u7 U( P0 e
signal SWCNT : std_logic_vector(2 downto 0);
8 Z B7 l+ O" u) x _! P8 ?& N* ?. usignal PWMCNT : std_logic_vector(2 downto 0);2 e( p- ~' z5 I8 C( q
signal DISP : std_logic;
$ `3 n: T# w; Z7 `' c2 N) M" L v2 k( G
begin
) ?; L1 Q4 a% }3 q8 z
( L/ \( i% C% u" n3 z--toggle switch input counter
& T5 {$ ]. z2 l/ ?! ^, k8 _process(RST,SW)
% w* \" k' x7 @; ~4 H6 Nbegin# p3 l4 `" \* D; S$ c: H: A
if RST='1' then; j# ?" E# r F! x: N' _
SWCNT<="000";$ e3 g; z4 n6 P! i9 u7 j0 d
elsif rising_edge(SW) then
: s, |$ O* P: d# K SWCNT<=SWCNT+'1';
* x+ T: B2 Z8 J end if;/ `* ^6 n0 h/ A& ~! q. k; K& E
end process;9 }5 ~; k) ]- |4 c* Q
# w' i; \7 p6 p; ^--pwm counter
0 Q0 z& K8 b: n2 W) Hprocess(RST,CLK)( W, ]9 p+ u \' h" a4 ^( Z1 F
begin
8 _% _2 G5 ~/ h7 V if RST='1' then
- T+ V% p+ |4 c: I PWMCNT<="000";- B( F6 t! t# @1 z
DISP<='0';/ t+ m8 a$ X/ r5 x& K* `
elsif rising_edge(CLK) then+ V4 |% `/ ?5 s: f+ a8 I
PWMCNT<=PWMCNT+'1';' f8 B' r* }! {5 l; T- o
if (PWMCNT="111") then2 F1 L8 N) C) o! J D" e
DISP<='1';: l1 G% V/ y: b; z. F4 o `
elsif (PWMCNT=SWCNT) then% Y A5 g# ~1 z' k/ w2 V# e
DISP<='0';
% x3 G2 H& Z, r end if;; ~$ x9 o/ A. w$ b6 R9 A1 K
end if;
& @8 p; ^: v# O# N& Xend process;$ _, y* N! M* B$ B
' P, d% n6 _/ | Y
--7-segment display decoder
; G% \# V( i9 o. A5 o) kprocess(DISP,SWCNT)7 \! _: a8 w& t. E Y
variable DISPEN : std_logic_vector(3 downto 0);
' z; a. U# R9 g: a, Abegin# m. q' C0 P% U# C
DISPEN := DISP SWCNT;
3 c2 S" Z" ?3 Z/ o$ q( X case DISPEN is --SEG7<="abcdefg"2 {# o8 t$ O6 g
when "1000"=>SEG7<="1111110";1 }. Z7 S) v' i" s& `5 t2 z
when "1001"=>SEG7<="0110000";9 P: E! C$ _5 e* M% ]
when "1010"=>SEG7<="1101101";
1 c- x0 [3 [; t' t when "1011"=>SEG7<="1111001";
9 g0 G- L( L6 H, q- ?/ V when "1100"=>SEG7<="0110011";
: _/ G$ M$ C0 _ when "1101"=>SEG7<="1011011";+ f$ G$ @( W( k
when "1110"=>SEG7<="1011111";
3 \! Y; ~$ ?* ~( v. Q" ]* K: R when "1111"=>SEG7<="1110000";
5 l. T$ ]6 z6 ]4 w5 D% v when others=>SEG7<="0000000";
! I, A2 B& E+ q W! V6 j end case;
7 a9 W/ R% F; S& w; G; r3 W B* X3 Cend process;' \0 I9 h A% B6 A) w. a; a1 i0 Q( w
end arch; |
|