|
此程式為一個每按一次TACT SW就會進行累加1的程式,並且LED亮度會每累加一次
) u7 v9 G. L7 `6 B% B就會增加,共8段亮度(0~7),此程式這些功能都可以了,但是會有開關彈跳的問題,
0 b' Y% J) w+ y' q, s希望能有高手幫我解決此問題
2 `$ M. n2 f7 W& A' m
* h# u ^- N4 N D* V V3 V. ~- q4 h l2 r4 b' { S3 p
library ieee;
1 ~4 d" Z2 Y/ b' n7 ~$ Nuse ieee.std_logic_1164.all;
0 Y4 I4 F# h& z# R$ w' }1 buse ieee.std_logic_arith.all;4 O A2 ~4 b, Z) ~8 E4 v% S. b
use ieee.std_logic_unsigned.all;
& F) p. M6 B0 `6 v- X7 ~0 u
1 \3 B5 }7 j1 w/ Rentity pwm8 is Port (8 f, {' R0 ^9 G
CLK : in std_logic;--clock 1KHZ
! {9 L) m8 j7 u- M6 X0 H X; X. f RST : in std_logic;--reset
& n; `$ n% F# a* n0 u SW : in std_logic;--switch in
U. Q" [6 l( E" z SEG7 : out std_logic_vector(6 downto 0));--
. |4 q6 `7 D9 ?) ~0 |* xend pwm8;
) r# M6 ^; H) K5 V3 H, i' O2 z
$ }: R# ~/ w1 s, G8 }/ j( \6 z& rarchitecture arch of pwm8 is8 `/ g+ t( Q* M- k, U/ Z1 t
* m% y! V9 {- X6 `) dsignal SWCNT : std_logic_vector(2 downto 0);
, _: w4 w" A/ Dsignal PWMCNT : std_logic_vector(2 downto 0);) G( C0 {" \$ z8 y+ G
signal DISP : std_logic;
0 t3 M& e' Y' W9 D/ s- Z. N. a4 a- r" o8 Q6 W! g/ l
begin: E% j) [8 p2 J, z/ K1 t! }
8 Z1 \3 ]5 S6 D2 U5 N+ {& S, l2 s--toggle switch input counter" E _& z" I& \
process(RST,SW)
9 g# S- D/ G' A' N3 [' r1 Hbegin0 H/ t. h; x7 w7 X
if RST='1' then" Z5 u3 w& U2 G8 _
SWCNT<="000";4 ~! M3 @3 k) `
elsif rising_edge(SW) then8 f( W" x, g2 l$ o% D! { x1 s
SWCNT<=SWCNT+'1';
3 Q. T& n( q6 o' q: D/ S6 B end if;
; A4 V# C% M4 I* N, tend process;* \( C; \; m; O# t" Y3 Z' Q
( T' h' o- z2 X) R4 I, Z$ x
--pwm counter. ^# M: T% N, b# K) j+ Q
process(RST,CLK)6 j" C3 b4 @; L* j3 b! w! t. E3 y
begin, e+ [. _9 l7 E0 u% ?9 U- I+ v, z
if RST='1' then
0 r" b& r, t$ O( b/ Y" b# n PWMCNT<="000";
, u: @/ J# ~3 m( J t DISP<='0';" s5 s) K. i3 g9 o! `2 u5 e
elsif rising_edge(CLK) then
: h- x; H/ f7 o! M. J/ z K PWMCNT<=PWMCNT+'1';
% q# I3 ~2 [( p0 O- O if (PWMCNT="111") then
9 \. Y( P, B+ p/ f DISP<='1';2 I7 K# Z2 D) N% C+ J
elsif (PWMCNT=SWCNT) then O8 u) ?% z4 f( H9 l( a
DISP<='0';5 q/ h9 [: n2 s" {9 Y9 s! L
end if;
' X1 }. y2 ~" I9 p2 d% I end if;$ H9 y+ a# `& v! h/ A* ^( l& ^
end process;8 w" v' C: |( U
6 o, v; r6 c' q* U, w3 s3 x6 z--7-segment display decoder
! C, U m, J4 T5 \5 gprocess(DISP,SWCNT)
/ F+ c% T, J7 Q+ u; j6 Mvariable DISPEN : std_logic_vector(3 downto 0);( J* J/ e1 {" p, L- Q& O& p5 J
begin
7 t2 p$ [. z9 L2 x DISPEN := DISP SWCNT;9 o3 W, |% v# d: u( e
case DISPEN is --SEG7<="abcdefg". I+ P; X8 M1 o2 S' j$ R7 Y
when "1000"=>SEG7<="1111110";
/ G, S; \& K- B when "1001"=>SEG7<="0110000";
: o/ W" O p; V/ V! t$ s when "1010"=>SEG7<="1101101";
* f0 c, t: b G( p- _( ]9 F8 x. ` when "1011"=>SEG7<="1111001";" j1 M4 r1 c# k, q( o: f/ z( \
when "1100"=>SEG7<="0110011";2 o; h6 N2 g& E+ h
when "1101"=>SEG7<="1011011";3 N( q# H1 {, o* J
when "1110"=>SEG7<="1011111";
8 d5 M _5 P. b' ~/ V& [ when "1111"=>SEG7<="1110000";
4 N/ l# X9 M$ v& h when others=>SEG7<="0000000";
5 e* U& \, j( j# v end case;
7 x$ ]! L7 \, M+ X& Kend process;& c. _: ^( b/ w
end arch; |
|