|
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次
1 C* P; [3 s2 |( X# m0 ~就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,
/ E+ x ^9 y/ S5 @5 a# @0 m* N$ O希望能有高手幫我解決此問題* \" ?. {; [5 D
- Y" ~3 d+ B. C. F% @) d; |4 {8 ^7 C6 N' ~
library ieee;
" h# w% p5 x5 O% _use ieee.std_logic_1164.all;
7 x. V. e5 t# \! [1 guse ieee.std_logic_arith.all;
" S; p5 t* n. Tuse ieee.std_logic_unsigned.all;, [4 Q" v# }" H& X# ^
' X) _4 O, c1 Z5 K
entity pwm8 is Port (0 N( [+ W' [$ C# g+ l5 C8 w/ j
CLK : in std_logic;--clock 1KHZ% o, E' H. P- p+ a7 @: b+ p6 L9 D: k
RST : in std_logic;--reset
2 M: r3 B7 r0 E7 X9 d0 R/ |; C SW : in std_logic;--switch in
4 Y/ c% h5 V9 C. N% z SEG7 : out std_logic_vector(6 downto 0));--* B" L0 g/ O- g% r+ ^* X
end pwm8;9 g* e: e# M1 m7 v- s
" R) H1 j- u& Y- Rarchitecture arch of pwm8 is. {) h/ ^, l; _0 m3 I7 P' A$ t
+ w, H7 ]( O3 {$ V- V: t; Psignal SWCNT : std_logic_vector(2 downto 0);
- w7 w4 i! P; e& Z9 @' I& Ssignal PWMCNT : std_logic_vector(2 downto 0);" c8 J3 z) q% L" }1 Y
signal DISP : std_logic;2 z' l2 i( r+ J* \2 p6 D5 f4 A
! }9 r% Z/ j2 |3 {. O( o0 f1 a
begin
2 G* U+ t4 ?% x4 R; U' R
/ [- j3 F. z6 G" U0 r--toggle switch input counter% y, ?% @+ s3 [( b9 J/ B% T
process(RST,SW)* ]! F$ F3 x6 {( w% d- c$ a4 y2 b8 E
begin% W( Z. B# D( U! ~& p8 U
if RST='1' then
/ Y" [3 A- ?& g0 N: h SWCNT<="000";
6 o8 `0 c) y+ @* u! b elsif rising_edge(SW) then
9 o6 r9 }- v* z" Z3 D/ ] SWCNT<=SWCNT+'1';# l1 M1 V) p" ~% U- h0 V p, ~: U, U
end if;
2 ~; ~* _" _' J8 X# qend process;
& M, F3 a$ }" W/ l5 P0 R4 e# Z5 O! J: O4 W3 F
--pwm counter
* w! L# G0 t( f4 r1 e8 S5 B4 q3 m+ aprocess(RST,CLK)1 d- y9 H7 I* P" ~$ r( ^. c" H
begin9 _4 W0 N$ p( S, S; r9 L2 f
if RST='1' then
! @) c% @9 X# e6 O9 ^) R PWMCNT<="000";0 b3 G# V$ e! l& l
DISP<='0';
+ O+ ?; m+ J/ }; {; D elsif rising_edge(CLK) then/ ~5 m" ~, p0 D- `4 V: u
PWMCNT<=PWMCNT+'1';; P8 U9 V2 Y- C
if (PWMCNT="111") then" Z1 n& }4 l3 w! t
DISP<='1'; Y, k+ T m4 N8 y$ V
elsif (PWMCNT=SWCNT) then
% K% |, \# c3 u/ G9 y) p DISP<='0';* | e( x4 b6 ]* b& T
end if;
# W( h3 N* J/ H. Z: J' Z& A end if;
[% |( }# a8 V% Cend process;
p( ~! v' D% U1 z" r0 u `3 U; k/ n0 v
--7-segment display decoder- C( B e* M7 L0 V1 H
process(DISP,SWCNT)
+ P3 n: S5 @% [$ r. W, }' Evariable DISPEN : std_logic_vector(3 downto 0);
% N# B2 e# ?) ` a! a( wbegin
A) ?# a+ Y' V8 o) ?" b. d DISPEN := DISP SWCNT;
5 Y% Q) P' W7 h) w7 d& i! b& v) O! U case DISPEN is --SEG7<="abcdefg"
7 ?# ?+ r3 L7 A2 s8 g when "1000"=>SEG7<="1111110";
) T! H6 i9 @ C1 r9 d6 |1 J when "1001"=>SEG7<="0110000";' W1 B' {. y! |
when "1010"=>SEG7<="1101101";' ?' M ~) o6 C( S" {4 }
when "1011"=>SEG7<="1111001";
4 H7 h! C9 d; I% W9 W/ ~ when "1100"=>SEG7<="0110011";" t$ e& W2 Q3 ]# ~& r+ r
when "1101"=>SEG7<="1011011";
$ Q, k% N2 S& I( t! V: I+ E when "1110"=>SEG7<="1011111";
+ s) i9 H8 C# Y when "1111"=>SEG7<="1110000";9 m( N+ P& R. ~3 P
when others=>SEG7<="0000000";
8 h% f( @4 F" y$ s% o end case;
9 _$ X4 F. Z) B( Z. o) }- W' hend process;
|9 ]+ ^7 p% f/ Q* d5 M8 lend arch; |
|